[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,15 +1179,19 @@ export const offersProfileRouter = createRouter()
data: { data: {
internshipCycle: internshipCycle:
offerToUpdate.offersIntern.internshipCycle ?? undefined, offerToUpdate.offersIntern.internshipCycle ?? undefined,
startYear: offerToUpdate.offersIntern.startYear ?? undefined, monthlySalary: {
title: offerToUpdate.offersIntern.title, upsert: {
}, create: {
where: { baseCurrency: baseCurrencyString,
id: offerToUpdate.offersIntern.id, baseValue: await convert(
offerToUpdate.offersIntern.monthlySalary.value,
offerToUpdate.offersIntern.monthlySalary.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersIntern.monthlySalary.currency,
value: offerToUpdate.offersIntern.monthlySalary.value,
}, },
}); update: {
await ctx.prisma.offersCurrency.update({
data: {
baseCurrency: baseCurrencyString, baseCurrency: baseCurrencyString,
baseValue: await convert( baseValue: await convert(
offerToUpdate.offersIntern.monthlySalary.value, offerToUpdate.offersIntern.monthlySalary.value,
@ -1196,9 +1200,14 @@ export const offersProfileRouter = createRouter()
), ),
currency: offerToUpdate.offersIntern.monthlySalary.currency, currency: offerToUpdate.offersIntern.monthlySalary.currency,
value: offerToUpdate.offersIntern.monthlySalary.value, value: offerToUpdate.offersIntern.monthlySalary.value,
}
}
},
startYear: offerToUpdate.offersIntern.startYear ?? undefined,
title: offerToUpdate.offersIntern.title
}, },
where: { where: {
id: offerToUpdate.offersIntern.monthlySalary.id, id: offerToUpdate.offersIntern.id,
}, },
}); });
} }
@ -1214,8 +1223,21 @@ 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: {
baseSalary: {
upsert: {
create: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
offerToUpdate.offersFullTime.baseSalary.value,
offerToUpdate.offersFullTime.baseSalary.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersFullTime.baseSalary.currency,
value: offerToUpdate.offersFullTime.baseSalary.value,
},
update: {
baseCurrency: baseCurrencyString, baseCurrency: baseCurrencyString,
baseValue: await convert( baseValue: await convert(
offerToUpdate.offersFullTime.baseSalary.value, offerToUpdate.offersFullTime.baseSalary.value,
@ -1224,15 +1246,21 @@ export const offersProfileRouter = createRouter()
), ),
currency: offerToUpdate.offersFullTime.baseSalary.currency, currency: offerToUpdate.offersFullTime.baseSalary.currency,
value: offerToUpdate.offersFullTime.baseSalary.value, 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: {
bonus: {
upsert: {
create: {
baseCurrency: baseCurrencyString, baseCurrency: baseCurrencyString,
baseValue: await convert( baseValue: await convert(
offerToUpdate.offersFullTime.bonus.value, offerToUpdate.offersFullTime.bonus.value,
@ -1242,14 +1270,30 @@ export const offersProfileRouter = createRouter()
currency: offerToUpdate.offersFullTime.bonus.currency, currency: offerToUpdate.offersFullTime.bonus.currency,
value: offerToUpdate.offersFullTime.bonus.value, 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: {
stocks: {
upsert: {
create: {
baseCurrency: baseCurrencyString, baseCurrency: baseCurrencyString,
baseValue: await convert( baseValue: await convert(
offerToUpdate.offersFullTime.stocks.value, offerToUpdate.offersFullTime.stocks.value,
@ -1259,25 +1303,53 @@ export const offersProfileRouter = createRouter()
currency: offerToUpdate.offersFullTime.stocks.currency, currency: offerToUpdate.offersFullTime.stocks.currency,
value: offerToUpdate.offersFullTime.stocks.value, 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: {
totalCompensation: {
upsert: {
create: {
baseCurrency: baseCurrencyString, baseCurrency: baseCurrencyString,
baseValue: await convert( baseValue: await convert(
offerToUpdate.offersFullTime.totalCompensation.value, offerToUpdate.offersFullTime.totalCompensation.value,
offerToUpdate.offersFullTime.totalCompensation.currency, offerToUpdate.offersFullTime.totalCompensation.currency,
baseCurrencyString, baseCurrencyString,
), ),
currency: currency: offerToUpdate.offersFullTime.totalCompensation.currency,
value: offerToUpdate.offersFullTime.totalCompensation.value,
},
update: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
offerToUpdate.offersFullTime.totalCompensation.value,
offerToUpdate.offersFullTime.totalCompensation.currency, offerToUpdate.offersFullTime.totalCompensation.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersFullTime.totalCompensation.currency,
value: offerToUpdate.offersFullTime.totalCompensation.value, value: offerToUpdate.offersFullTime.totalCompensation.value,
}
}
}
}, },
where: { where: {
id: offerToUpdate.offersFullTime.totalCompensation.id, id: offerToUpdate.offersFullTime.id,
}, },
}); });
} }

Loading…
Cancel
Save