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

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

@ -786,26 +786,10 @@ 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: {
baseCurrency: baseCurrencyString, upsert: {
baseValue: await convert(
exp.monthlySalary.value,
exp.monthlySalary.currency,
baseCurrencyString,
),
currency: exp.monthlySalary.currency,
value: exp.monthlySalary.value,
},
where: {
id: exp.monthlySalary.id,
},
});
} else {
await ctx.prisma.offersExperience.update({
data: {
monthlySalary: {
create: { create: {
baseCurrency: baseCurrencyString, baseCurrency: baseCurrencyString,
baseValue: await convert( baseValue: await convert(
@ -816,36 +800,30 @@ export const offersProfileRouter = createRouter()
currency: exp.monthlySalary.currency, currency: exp.monthlySalary.currency,
value: exp.monthlySalary.value, value: exp.monthlySalary.value,
}, },
}, update: {
}, baseCurrency: baseCurrencyString,
where: { baseValue: await convert(
id: exp.id, exp.monthlySalary.value,
}, exp.monthlySalary.currency,
}); baseCurrencyString,
} ),
currency: exp.monthlySalary.currency,
value: exp.monthlySalary.value,
}
}
}
},
where: {
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: {
baseCurrency: baseCurrencyString, upsert: {
baseValue: await convert(
exp.totalCompensation.value,
exp.totalCompensation.currency,
baseCurrencyString,
),
currency: exp.totalCompensation.currency,
value: exp.totalCompensation.value,
},
where: {
id: exp.totalCompensation.id,
},
});
} else {
await ctx.prisma.offersExperience.update({
data: {
totalCompensation: {
create: { create: {
baseCurrency: baseCurrencyString, baseCurrency: baseCurrencyString,
baseValue: await convert( baseValue: await convert(
@ -856,13 +834,23 @@ export const offersProfileRouter = createRouter()
currency: exp.totalCompensation.currency, currency: exp.totalCompensation.currency,
value: exp.totalCompensation.value, value: exp.totalCompensation.value,
}, },
}, update: {
}, baseCurrency: baseCurrencyString,
where: { baseValue: await convert(
id: exp.id, exp.totalCompensation.value,
}, exp.totalCompensation.currency,
}); baseCurrencyString,
} ),
currency: exp.totalCompensation.currency,
value: exp.totalCompensation.value,
}
}
}
},
where: {
id: exp.id
}
})
} }
} else if (!exp.id) { } else if (!exp.id) {
// Create new experience // Create new experience

Loading…
Cancel
Save