From 252feda82d99faa7057cff2042b2e339fecbc33b Mon Sep 17 00:00:00 2001 From: Bryann Yeap Kok Keong Date: Mon, 31 Oct 2022 14:09:57 +0800 Subject: [PATCH] [offers][chore] Change location in schema --- .../migration.sql | 21 +++ apps/portal/prisma/schema.prisma | 8 +- .../router/offers/offers-profile-router.ts | 155 +++++++++++++----- 3 files changed, 143 insertions(+), 41 deletions(-) create mode 100644 apps/portal/prisma/migrations/20221102121331_update_location_for_offers/migration.sql diff --git a/apps/portal/prisma/migrations/20221102121331_update_location_for_offers/migration.sql b/apps/portal/prisma/migrations/20221102121331_update_location_for_offers/migration.sql new file mode 100644 index 00000000..06a7d7af --- /dev/null +++ b/apps/portal/prisma/migrations/20221102121331_update_location_for_offers/migration.sql @@ -0,0 +1,21 @@ +/* + Warnings: + + - You are about to drop the column `location` on the `OffersExperience` table. All the data in the column will be lost. + - You are about to drop the column `location` on the `OffersOffer` table. All the data in the column will be lost. + - Added the required column `cityId` to the `OffersOffer` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "OffersExperience" DROP COLUMN "location", +ADD COLUMN "cityId" TEXT; + +-- AlterTable +ALTER TABLE "OffersOffer" DROP COLUMN "location", +ADD COLUMN "cityId" TEXT NOT NULL; + +-- AddForeignKey +ALTER TABLE "OffersExperience" ADD CONSTRAINT "OffersExperience_cityId_fkey" FOREIGN KEY ("cityId") REFERENCES "City"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "OffersOffer" ADD CONSTRAINT "OffersOffer_cityId_fkey" FOREIGN KEY ("cityId") REFERENCES "City"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/apps/portal/prisma/schema.prisma b/apps/portal/prisma/schema.prisma index b2820c3c..b6873fde 100644 --- a/apps/portal/prisma/schema.prisma +++ b/apps/portal/prisma/schema.prisma @@ -131,6 +131,8 @@ model City { stateId String state State @relation(fields: [stateId], references: [id]) questionsQuestionEncounters QuestionsQuestionEncounter[] + OffersExperience OffersExperience[] + OffersOffer OffersOffer[] @@unique([name, stateId]) } @@ -265,7 +267,8 @@ model OffersExperience { // Add more fields durationInMonths Int? - location String? + location City? @relation(fields: [cityId], references: [id]) + cityId String? // FULLTIME fields level String? @@ -348,8 +351,9 @@ model OffersOffer { company Company @relation(fields: [companyId], references: [id]) companyId String + location City @relation(fields: [cityId], references: [id]) + cityId String monthYearReceived DateTime - location String negotiationStrategy String comments String 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 e25bb076..16a88114 100644 --- a/apps/portal/src/server/router/offers/offers-profile-router.ts +++ b/apps/portal/src/server/router/offers/offers-profile-router.ts @@ -171,6 +171,15 @@ export const offersProfileRouter = createRouter() topSimilarOffers: { include: { company: true, + location: { + include: { + state: { + include: { + country: true, + }, + }, + }, + }, offersFullTime: { include: { totalCompensation: true, @@ -188,6 +197,15 @@ export const offersProfileRouter = createRouter() experiences: { include: { company: true, + location: { + include: { + state: { + include: { + country: true, + }, + }, + }, + }, }, }, }, @@ -203,6 +221,15 @@ export const offersProfileRouter = createRouter() topSimilarOffers: { include: { company: true, + location: { + include: { + state: { + include: { + country: true, + }, + }, + }, + }, offersFullTime: { include: { totalCompensation: true, @@ -220,6 +247,15 @@ export const offersProfileRouter = createRouter() experiences: { include: { company: true, + location: { + include: { + state: { + include: { + country: true, + }, + }, + }, + }, }, }, }, @@ -233,6 +269,15 @@ export const offersProfileRouter = createRouter() overallHighestOffer: { include: { company: true, + location: { + include: { + state: { + include: { + country: true, + }, + }, + }, + }, offersFullTime: { include: { totalCompensation: true, @@ -258,6 +303,15 @@ export const offersProfileRouter = createRouter() experiences: { include: { company: true, + location: { + include: { + state: { + include: { + country: true, + }, + }, + }, + }, monthlySalary: true, totalCompensation: true, }, @@ -275,6 +329,15 @@ export const offersProfileRouter = createRouter() offers: { include: { company: true, + location: { + include: { + state: { + include: { + country: true, + }, + }, + }, + }, offersFullTime: { include: { baseSalary: true, @@ -809,14 +872,14 @@ export const offersProfileRouter = createRouter() ), currency: exp.monthlySalary.currency, value: exp.monthlySalary.value, - } - } - } + }, + }, + }, }, where: { - id: exp.id - } - }) + id: exp.id, + }, + }); } if (exp.totalCompensation) { @@ -843,14 +906,14 @@ export const offersProfileRouter = createRouter() ), currency: exp.totalCompensation.currency, value: exp.totalCompensation.value, - } - } - } + }, + }, + }, }, where: { - id: exp.id - } - }) + id: exp.id, + }, + }); } } else if (!exp.id) { // Create new experience @@ -1176,7 +1239,8 @@ export const offersProfileRouter = createRouter() offerToUpdate.offersIntern.monthlySalary.currency, baseCurrencyString, ), - currency: offerToUpdate.offersIntern.monthlySalary.currency, + currency: + offerToUpdate.offersIntern.monthlySalary.currency, value: offerToUpdate.offersIntern.monthlySalary.value, }, update: { @@ -1186,13 +1250,14 @@ export const offersProfileRouter = createRouter() offerToUpdate.offersIntern.monthlySalary.currency, baseCurrencyString, ), - currency: offerToUpdate.offersIntern.monthlySalary.currency, + currency: + offerToUpdate.offersIntern.monthlySalary.currency, value: offerToUpdate.offersIntern.monthlySalary.value, - } - } + }, + }, }, startYear: offerToUpdate.offersIntern.startYear ?? undefined, - title: offerToUpdate.offersIntern.title + title: offerToUpdate.offersIntern.title, }, where: { id: offerToUpdate.offersIntern.id, @@ -1222,7 +1287,8 @@ export const offersProfileRouter = createRouter() offerToUpdate.offersFullTime.baseSalary.currency, baseCurrencyString, ), - currency: offerToUpdate.offersFullTime.baseSalary.currency, + currency: + offerToUpdate.offersFullTime.baseSalary.currency, value: offerToUpdate.offersFullTime.baseSalary.value, }, update: { @@ -1232,11 +1298,12 @@ export const offersProfileRouter = createRouter() offerToUpdate.offersFullTime.baseSalary.currency, baseCurrencyString, ), - currency: offerToUpdate.offersFullTime.baseSalary.currency, + currency: + offerToUpdate.offersFullTime.baseSalary.currency, value: offerToUpdate.offersFullTime.baseSalary.value, - } - } - } + }, + }, + }, }, where: { id: offerToUpdate.offersFullTime.id, @@ -1267,9 +1334,9 @@ export const offersProfileRouter = createRouter() ), currency: offerToUpdate.offersFullTime.bonus.currency, value: offerToUpdate.offersFullTime.bonus.value, - } - } - } + }, + }, + }, }, where: { id: offerToUpdate.offersFullTime.id, @@ -1288,7 +1355,8 @@ export const offersProfileRouter = createRouter() offerToUpdate.offersFullTime.stocks.currency, baseCurrencyString, ), - currency: offerToUpdate.offersFullTime.stocks.currency, + currency: + offerToUpdate.offersFullTime.stocks.currency, value: offerToUpdate.offersFullTime.stocks.value, }, update: { @@ -1298,11 +1366,12 @@ export const offersProfileRouter = createRouter() offerToUpdate.offersFullTime.stocks.currency, baseCurrencyString, ), - currency: offerToUpdate.offersFullTime.stocks.currency, + currency: + offerToUpdate.offersFullTime.stocks.currency, value: offerToUpdate.offersFullTime.stocks.value, - } - } - } + }, + }, + }, }, where: { id: offerToUpdate.offersFullTime.id, @@ -1317,24 +1386,32 @@ export const offersProfileRouter = createRouter() 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, + 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, - } - } - } + currency: + offerToUpdate.offersFullTime.totalCompensation + .currency, + value: + offerToUpdate.offersFullTime.totalCompensation.value, + }, + }, + }, }, where: { id: offerToUpdate.offersFullTime.id,