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

Loading…
Cancel
Save