[offers][feat] integrate location with update profile endpoint

pull/501/head^2
Stuart Long Chay Boon 3 years ago
parent 89644e8c2b
commit bebbebf9dc

@ -1035,35 +1035,110 @@ export const offersProfileRouter = createRouter()
exp.totalCompensation?.currency != null &&
exp.totalCompensation?.value != null
) {
// FULLTIME
if (exp.companyId) {
if (exp.cityId) {
await ctx.prisma.offersBackground.update({
data: {
experiences: {
create: {
company: {
connect: {
id: exp.companyId,
},
},
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
level: exp.level,
location: {
connect: {
id: exp.cityId
}
},
title: exp.title,
totalCompensation: exp.totalCompensation
? {
create: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
exp.totalCompensation.value,
exp.totalCompensation.currency,
baseCurrencyString,
),
currency: exp.totalCompensation.currency,
value: exp.totalCompensation.value,
},
}
: undefined,
},
},
},
where: {
id: input.background.id,
},
});
} else {
await ctx.prisma.offersBackground.update({
data: {
experiences: {
create: {
company: {
connect: {
id: exp.companyId,
},
},
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
level: exp.level,
title: exp.title,
totalCompensation: exp.totalCompensation
? {
create: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
exp.totalCompensation.value,
exp.totalCompensation.currency,
baseCurrencyString,
),
currency: exp.totalCompensation.currency,
value: exp.totalCompensation.value,
},
}
: undefined,
},
},
},
where: {
id: input.background.id,
},
});
}
} else if (exp.cityId) {
await ctx.prisma.offersBackground.update({
data: {
experiences: {
create: {
company: {
connect: {
id: exp.companyId,
},
},
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
level: exp.level,
location: exp.location,
location: {
connect: {
id: exp.cityId
}
},
title: exp.title,
totalCompensation: exp.totalCompensation
? {
create: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
exp.totalCompensation.value,
exp.totalCompensation.currency,
baseCurrencyString,
),
currency: exp.totalCompensation.currency,
value: exp.totalCompensation.value,
},
}
: undefined,
totalCompensation: {
create: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
exp.totalCompensation.value,
exp.totalCompensation.currency,
baseCurrencyString,
),
currency: exp.totalCompensation.currency,
value: exp.totalCompensation.value,
},
},
},
},
},
@ -1079,7 +1154,6 @@ export const offersProfileRouter = createRouter()
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
level: exp.level,
location: exp.location,
title: exp.title,
totalCompensation: {
create: {
@ -1102,19 +1176,67 @@ export const offersProfileRouter = createRouter()
});
}
} else if (exp.companyId) {
if (exp.cityId) {
await ctx.prisma.offersBackground.update({
data: {
experiences: {
create: {
company: {
connect: {
id: exp.companyId,
},
},
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
level: exp.level,
location: {
connect: {
id: exp.cityId
}
},
title: exp.title,
},
},
},
where: {
id: input.background.id,
},
});
} else {
await ctx.prisma.offersBackground.update({
data: {
experiences: {
create: {
company: {
connect: {
id: exp.companyId,
},
},
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
level: exp.level,
title: exp.title,
},
},
},
where: {
id: input.background.id,
},
});
}
} else if (exp.cityId) {
await ctx.prisma.offersBackground.update({
data: {
experiences: {
create: {
company: {
connect: {
id: exp.companyId,
},
},
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
level: exp.level,
location: exp.location,
location: {
connect: {
id: exp.cityId
}
},
title: exp.title,
},
},
@ -1131,7 +1253,6 @@ export const offersProfileRouter = createRouter()
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
level: exp.level,
location: exp.location,
title: exp.title,
},
},
@ -1146,19 +1267,90 @@ export const offersProfileRouter = createRouter()
exp.monthlySalary?.currency != null &&
exp.monthlySalary?.value != null
) {
// INTERN
if (exp.companyId) {
if (exp.cityId) {
await ctx.prisma.offersBackground.update({
data: {
experiences: {
create: {
company: {
connect: {
id: exp.companyId,
},
},
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
location: {
connect: {
id: exp.cityId
}
},
monthlySalary: {
create: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
exp.monthlySalary.value,
exp.monthlySalary.currency,
baseCurrencyString,
),
currency: exp.monthlySalary.currency,
value: exp.monthlySalary.value,
},
},
title: exp.title,
},
},
},
where: {
id: input.background.id,
},
});
} else {
await ctx.prisma.offersBackground.update({
data: {
experiences: {
create: {
company: {
connect: {
id: exp.companyId,
},
},
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
monthlySalary: {
create: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
exp.monthlySalary.value,
exp.monthlySalary.currency,
baseCurrencyString,
),
currency: exp.monthlySalary.currency,
value: exp.monthlySalary.value,
},
},
title: exp.title,
},
},
},
where: {
id: input.background.id,
},
});
}
} else if (exp.cityId) {
await ctx.prisma.offersBackground.update({
data: {
experiences: {
create: {
company: {
connect: {
id: exp.companyId,
},
},
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
location: exp.location,
location: {
connect: {
id: exp.cityId
}
},
monthlySalary: {
create: {
baseCurrency: baseCurrencyString,
@ -1186,7 +1378,6 @@ export const offersProfileRouter = createRouter()
create: {
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
location: exp.location,
monthlySalary: {
create: {
baseCurrency: baseCurrencyString,
@ -1209,18 +1400,64 @@ export const offersProfileRouter = createRouter()
});
}
} else if (exp.companyId) {
if (exp.cityId) {
await ctx.prisma.offersBackground.update({
data: {
experiences: {
create: {
company: {
connect: {
id: exp.companyId,
},
},
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
location: {
connect: {
id: exp.cityId,
}
},
title: exp.title,
},
},
},
where: {
id: input.background.id,
},
});
} else {
await ctx.prisma.offersBackground.update({
data: {
experiences: {
create: {
company: {
connect: {
id: exp.companyId,
},
},
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
title: exp.title,
},
},
},
where: {
id: input.background.id,
},
});
}
} else if (exp.cityId) {
await ctx.prisma.offersBackground.update({
data: {
experiences: {
create: {
company: {
connect: {
id: exp.companyId,
},
},
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
location: exp.location,
location: {
connect: {
id: exp.cityId
}
},
title: exp.title,
},
},
@ -1236,7 +1473,6 @@ export const offersProfileRouter = createRouter()
create: {
durationInMonths: exp.durationInMonths,
jobType: exp.jobType,
location: exp.location,
title: exp.title,
},
},
@ -1324,12 +1560,20 @@ export const offersProfileRouter = createRouter()
await ctx.prisma.offersOffer.update({
data: {
comments: offerToUpdate.comments,
companyId: offerToUpdate.companyId,
company: {
connect: {
id: offerToUpdate.companyId
}
},
jobType:
offerToUpdate.jobType === JobType.FULLTIME
? JobType.FULLTIME
: JobType.INTERN,
location: offerToUpdate.location,
location: {
connect: {
id: offerToUpdate.cityId
}
},
monthYearReceived: offerToUpdate.monthYearReceived,
negotiationStrategy: offerToUpdate.negotiationStrategy,
},
@ -1466,7 +1710,11 @@ export const offersProfileRouter = createRouter()
},
},
jobType: offerToUpdate.jobType,
location: offerToUpdate.location,
location: {
connect: {
id: offerToUpdate.cityId
}
},
monthYearReceived: offerToUpdate.monthYearReceived,
negotiationStrategy: offerToUpdate.negotiationStrategy,
offersIntern: {
@ -1520,7 +1768,11 @@ export const offersProfileRouter = createRouter()
},
},
jobType: offerToUpdate.jobType,
location: offerToUpdate.location,
location: {
connect: {
id: offerToUpdate.cityId
}
},
monthYearReceived: offerToUpdate.monthYearReceived,
negotiationStrategy: offerToUpdate.negotiationStrategy,
offersFullTime: {

Loading…
Cancel
Save