[offers][fix] use upsert to remove id in valuation

pull/492/head
Stuart Long Chay Boon 2 years ago
parent c3e8490656
commit ab7f064734

@ -786,9 +786,11 @@ export const offersProfileRouter = createRouter()
});
if (exp.monthlySalary) {
if (exp.monthlySalary.id) {
await ctx.prisma.offersCurrency.update({
await ctx.prisma.offersExperience.update({
data: {
monthlySalary: {
upsert: {
create: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
exp.monthlySalary.value,
@ -798,15 +800,7 @@ export const offersProfileRouter = createRouter()
currency: exp.monthlySalary.currency,
value: exp.monthlySalary.value,
},
where: {
id: exp.monthlySalary.id,
},
});
} else {
await ctx.prisma.offersExperience.update({
data: {
monthlySalary: {
create: {
update: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
exp.monthlySalary.value,
@ -815,20 +809,22 @@ export const offersProfileRouter = createRouter()
),
currency: exp.monthlySalary.currency,
value: exp.monthlySalary.value,
},
},
}
}
}
},
where: {
id: exp.id,
},
});
id: exp.id
}
})
}
if (exp.totalCompensation) {
if (exp.totalCompensation.id) {
await ctx.prisma.offersCurrency.update({
await ctx.prisma.offersExperience.update({
data: {
totalCompensation: {
upsert: {
create: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
exp.totalCompensation.value,
@ -838,15 +834,7 @@ export const offersProfileRouter = createRouter()
currency: exp.totalCompensation.currency,
value: exp.totalCompensation.value,
},
where: {
id: exp.totalCompensation.id,
},
});
} else {
await ctx.prisma.offersExperience.update({
data: {
totalCompensation: {
create: {
update: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
exp.totalCompensation.value,
@ -855,14 +843,14 @@ export const offersProfileRouter = createRouter()
),
currency: exp.totalCompensation.currency,
value: exp.totalCompensation.value,
},
},
}
}
}
},
where: {
id: exp.id,
},
});
id: exp.id
}
})
}
} else if (!exp.id) {
// Create new experience

Loading…
Cancel
Save