diff --git a/apps/portal/src/server/router/offers/offers-profile-router.ts b/apps/portal/src/server/router/offers/offers-profile-router.ts index 5f367098..e25bb076 100644 --- a/apps/portal/src/server/router/offers/offers-profile-router.ts +++ b/apps/portal/src/server/router/offers/offers-profile-router.ts @@ -786,26 +786,10 @@ export const offersProfileRouter = createRouter() }); if (exp.monthlySalary) { - if (exp.monthlySalary.id) { - await ctx.prisma.offersCurrency.update({ - data: { - baseCurrency: baseCurrencyString, - 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: { + await ctx.prisma.offersExperience.update({ + data: { + monthlySalary: { + upsert: { create: { baseCurrency: baseCurrencyString, baseValue: await convert( @@ -816,36 +800,30 @@ export const offersProfileRouter = createRouter() currency: exp.monthlySalary.currency, value: exp.monthlySalary.value, }, - }, - }, - where: { - id: exp.id, - }, - }); - } + update: { + baseCurrency: baseCurrencyString, + baseValue: await convert( + 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.id) { - await ctx.prisma.offersCurrency.update({ - data: { - baseCurrency: baseCurrencyString, - 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: { + await ctx.prisma.offersExperience.update({ + data: { + totalCompensation: { + upsert: { create: { baseCurrency: baseCurrencyString, baseValue: await convert( @@ -856,13 +834,23 @@ export const offersProfileRouter = createRouter() currency: exp.totalCompensation.currency, value: exp.totalCompensation.value, }, - }, - }, - where: { - id: exp.id, - }, - }); - } + update: { + baseCurrency: baseCurrencyString, + baseValue: await convert( + exp.totalCompensation.value, + exp.totalCompensation.currency, + baseCurrencyString, + ), + currency: exp.totalCompensation.currency, + value: exp.totalCompensation.value, + } + } + } + }, + where: { + id: exp.id + } + }) } } else if (!exp.id) { // Create new experience