[offers][fix] fix unable to update BBS in offer bug and remove valuation id

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

@ -1179,28 +1179,37 @@ export const offersProfileRouter = createRouter()
data: { data: {
internshipCycle: internshipCycle:
offerToUpdate.offersIntern.internshipCycle ?? undefined, offerToUpdate.offersIntern.internshipCycle ?? undefined,
monthlySalary: {
upsert: {
create: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
offerToUpdate.offersIntern.monthlySalary.value,
offerToUpdate.offersIntern.monthlySalary.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersIntern.monthlySalary.currency,
value: offerToUpdate.offersIntern.monthlySalary.value,
},
update: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
offerToUpdate.offersIntern.monthlySalary.value,
offerToUpdate.offersIntern.monthlySalary.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersIntern.monthlySalary.currency,
value: offerToUpdate.offersIntern.monthlySalary.value,
}
}
},
startYear: offerToUpdate.offersIntern.startYear ?? undefined, startYear: offerToUpdate.offersIntern.startYear ?? undefined,
title: offerToUpdate.offersIntern.title, title: offerToUpdate.offersIntern.title
}, },
where: { where: {
id: offerToUpdate.offersIntern.id, id: offerToUpdate.offersIntern.id,
}, },
}); });
await ctx.prisma.offersCurrency.update({
data: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
offerToUpdate.offersIntern.monthlySalary.value,
offerToUpdate.offersIntern.monthlySalary.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersIntern.monthlySalary.currency,
value: offerToUpdate.offersIntern.monthlySalary.value,
},
where: {
id: offerToUpdate.offersIntern.monthlySalary.id,
},
});
} }
if (offerToUpdate.offersFullTime?.totalCompensation != null) { if (offerToUpdate.offersFullTime?.totalCompensation != null) {
@ -1214,70 +1223,133 @@ export const offersProfileRouter = createRouter()
}, },
}); });
if (offerToUpdate.offersFullTime.baseSalary != null) { if (offerToUpdate.offersFullTime.baseSalary != null) {
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersFullTime.update({
data: { data: {
baseCurrency: baseCurrencyString, baseSalary: {
baseValue: await convert( upsert: {
offerToUpdate.offersFullTime.baseSalary.value, create: {
offerToUpdate.offersFullTime.baseSalary.currency, baseCurrency: baseCurrencyString,
baseCurrencyString, baseValue: await convert(
), offerToUpdate.offersFullTime.baseSalary.value,
currency: offerToUpdate.offersFullTime.baseSalary.currency, offerToUpdate.offersFullTime.baseSalary.currency,
value: offerToUpdate.offersFullTime.baseSalary.value, baseCurrencyString,
),
currency: offerToUpdate.offersFullTime.baseSalary.currency,
value: offerToUpdate.offersFullTime.baseSalary.value,
},
update: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
offerToUpdate.offersFullTime.baseSalary.value,
offerToUpdate.offersFullTime.baseSalary.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersFullTime.baseSalary.currency,
value: offerToUpdate.offersFullTime.baseSalary.value,
}
}
}
}, },
where: { where: {
id: offerToUpdate.offersFullTime.baseSalary.id, id: offerToUpdate.offersFullTime.id,
}, },
}); });
} }
if (offerToUpdate.offersFullTime.bonus != null) { if (offerToUpdate.offersFullTime.bonus != null) {
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersFullTime.update({
data: { data: {
baseCurrency: baseCurrencyString, bonus: {
baseValue: await convert( upsert: {
offerToUpdate.offersFullTime.bonus.value, create: {
offerToUpdate.offersFullTime.bonus.currency, baseCurrency: baseCurrencyString,
baseCurrencyString, baseValue: await convert(
), offerToUpdate.offersFullTime.bonus.value,
currency: offerToUpdate.offersFullTime.bonus.currency, offerToUpdate.offersFullTime.bonus.currency,
value: offerToUpdate.offersFullTime.bonus.value, baseCurrencyString,
),
currency: offerToUpdate.offersFullTime.bonus.currency,
value: offerToUpdate.offersFullTime.bonus.value,
},
update: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
offerToUpdate.offersFullTime.bonus.value,
offerToUpdate.offersFullTime.bonus.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersFullTime.bonus.currency,
value: offerToUpdate.offersFullTime.bonus.value,
}
}
}
}, },
where: { where: {
id: offerToUpdate.offersFullTime.bonus.id, id: offerToUpdate.offersFullTime.id,
}, },
}); });
} }
if (offerToUpdate.offersFullTime.stocks != null) { if (offerToUpdate.offersFullTime.stocks != null) {
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersFullTime.update({
data: { data: {
baseCurrency: baseCurrencyString, stocks: {
baseValue: await convert( upsert: {
offerToUpdate.offersFullTime.stocks.value, create: {
offerToUpdate.offersFullTime.stocks.currency, baseCurrency: baseCurrencyString,
baseCurrencyString, baseValue: await convert(
), offerToUpdate.offersFullTime.stocks.value,
currency: offerToUpdate.offersFullTime.stocks.currency, offerToUpdate.offersFullTime.stocks.currency,
value: offerToUpdate.offersFullTime.stocks.value, baseCurrencyString,
),
currency: offerToUpdate.offersFullTime.stocks.currency,
value: offerToUpdate.offersFullTime.stocks.value,
},
update: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
offerToUpdate.offersFullTime.stocks.value,
offerToUpdate.offersFullTime.stocks.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersFullTime.stocks.currency,
value: offerToUpdate.offersFullTime.stocks.value,
}
}
}
}, },
where: { where: {
id: offerToUpdate.offersFullTime.stocks.id, id: offerToUpdate.offersFullTime.id,
}, },
}); });
} }
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersFullTime.update({
data: { data: {
baseCurrency: baseCurrencyString, totalCompensation: {
baseValue: await convert( upsert: {
offerToUpdate.offersFullTime.totalCompensation.value, create: {
offerToUpdate.offersFullTime.totalCompensation.currency, baseCurrency: baseCurrencyString,
baseCurrencyString, baseValue: await convert(
), offerToUpdate.offersFullTime.totalCompensation.value,
currency: offerToUpdate.offersFullTime.totalCompensation.currency,
offerToUpdate.offersFullTime.totalCompensation.currency, baseCurrencyString,
value: offerToUpdate.offersFullTime.totalCompensation.value, ),
currency: offerToUpdate.offersFullTime.totalCompensation.currency,
value: offerToUpdate.offersFullTime.totalCompensation.value,
},
update: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
offerToUpdate.offersFullTime.totalCompensation.value,
offerToUpdate.offersFullTime.totalCompensation.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersFullTime.totalCompensation.currency,
value: offerToUpdate.offersFullTime.totalCompensation.value,
}
}
}
}, },
where: { where: {
id: offerToUpdate.offersFullTime.totalCompensation.id, id: offerToUpdate.offersFullTime.id,
}, },
}); });
} }

Loading…
Cancel
Save