From 6a6c939953b3e85516eb69b237ff860ef4b21458 Mon Sep 17 00:00:00 2001 From: Stuart Long Chay Boon Date: Tue, 11 Oct 2022 15:25:42 +0800 Subject: [PATCH] [offers][fix] fix create endpoint no company bug --- .../server/router/offers-profile-router.ts | 113 +++++++++++------- 1 file changed, 72 insertions(+), 41 deletions(-) diff --git a/apps/portal/src/server/router/offers-profile-router.ts b/apps/portal/src/server/router/offers-profile-router.ts index cdd01558..20343ac6 100644 --- a/apps/portal/src/server/router/offers-profile-router.ts +++ b/apps/portal/src/server/router/offers-profile-router.ts @@ -161,48 +161,79 @@ export const offersProfileRouter = createRouter() x.totalCompensation?.currency !== undefined && x.totalCompensation.value !== undefined ) { - return { - company: { - connect: { - id: x.companyId, - }, - }, - durationInMonths: x.durationInMonths, - jobType: x.jobType, - level: x.level, - specialization: x.specialization, - title: x.title, - totalCompensation: { - create: { - currency: x.totalCompensation?.currency, - value: x.totalCompensation?.value, - }, - }, - }; - } - if ( - x.jobType === 'INTERN' && - x.monthlySalary?.currency !== undefined && - x.monthlySalary.value !== undefined - ) { - return { - company: { - connect: { - id: x.companyId, - }, - }, - durationInMonths: x.durationInMonths, - jobType: x.jobType, - monthlySalary: { - create: { - currency: x.monthlySalary?.currency, - value: x.monthlySalary?.value, - }, - }, - specialization: x.specialization, - title: x.title, - }; + if (x.companyId) { + return { + company: { + connect: { + id: x.companyId, + }, + }, + durationInMonths: x.durationInMonths, + jobType: x.jobType, + level: x.level, + specialization: x.specialization, + title: x.title, + totalCompensation: { + create: { + currency: x.totalCompensation?.currency, + value: x.totalCompensation?.value, + }, + }, + }; + } + return { + durationInMonths: x.durationInMonths, + jobType: x.jobType, + level: x.level, + specialization: x.specialization, + title: x.title, + totalCompensation: { + create: { + currency: x.totalCompensation?.currency, + value: x.totalCompensation?.value, + }, + }, + }; + } + if ( + x.jobType === 'INTERN' && + x.monthlySalary?.currency !== undefined && + x.monthlySalary.value !== undefined + ) { + if (x.companyId) { + return { + company: { + connect: { + id: x.companyId, + }, + }, + durationInMonths: x.durationInMonths, + jobType: x.jobType, + monthlySalary: { + create: { + currency: x.monthlySalary?.currency, + value: x.monthlySalary?.value, + }, + }, + specialization: x.specialization, + title: x.title, + }; + } + return { + durationInMonths: x.durationInMonths, + jobType: x.jobType, + monthlySalary: { + create: { + currency: x.monthlySalary?.currency, + value: x.monthlySalary?.value, + }, + }, + specialization: x.specialization, + title: x.title, + }; + + } throw Prisma.PrismaClientKnownRequestError; }),