From ca17ef9162739aebd5e8a916ff6a2df316a9d9e1 Mon Sep 17 00:00:00 2001 From: Bryann Yeap Kok Keong Date: Thu, 3 Nov 2022 11:56:25 +0800 Subject: [PATCH] [offers][chore] Change company field in AnalysisUnit --- .../migration.sql | 13 ++++ apps/portal/prisma/schema.prisma | 5 +- apps/portal/src/mappers/offers-mappers.ts | 7 +- .../router/offers/offers-analysis-router.ts | 2 + .../router/offers/offers-profile-router.ts | 78 ++++++++++--------- .../src/utils/offers/analysisGeneration.ts | 16 +++- 6 files changed, 78 insertions(+), 43 deletions(-) create mode 100644 apps/portal/prisma/migrations/20221103031927_change_company_in_analysis_unit/migration.sql diff --git a/apps/portal/prisma/migrations/20221103031927_change_company_in_analysis_unit/migration.sql b/apps/portal/prisma/migrations/20221103031927_change_company_in_analysis_unit/migration.sql new file mode 100644 index 00000000..cf185e47 --- /dev/null +++ b/apps/portal/prisma/migrations/20221103031927_change_company_in_analysis_unit/migration.sql @@ -0,0 +1,13 @@ +/* + Warnings: + + - You are about to drop the column `companyName` on the `OffersAnalysisUnit` table. All the data in the column will be lost. + - Added the required column `companyId` to the `OffersAnalysisUnit` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "OffersAnalysisUnit" DROP COLUMN "companyName", +ADD COLUMN "companyId" TEXT NOT NULL; + +-- AddForeignKey +ALTER TABLE "OffersAnalysisUnit" ADD CONSTRAINT "OffersAnalysisUnit_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "Company"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/apps/portal/prisma/schema.prisma b/apps/portal/prisma/schema.prisma index b6873fde..e39941f2 100644 --- a/apps/portal/prisma/schema.prisma +++ b/apps/portal/prisma/schema.prisma @@ -104,6 +104,7 @@ model Company { questionsQuestionEncounter QuestionsQuestionEncounter[] OffersExperience OffersExperience[] OffersOffer OffersOffer[] + OffersAnalysisUnit OffersAnalysisUnit[] } model Country { @@ -418,7 +419,9 @@ model OffersAnalysis { model OffersAnalysisUnit { id String @id @default(cuid()) - companyName String + company Company @relation(fields: [companyId], references: [id]) + companyId String + percentile Float noOfSimilarOffers Int topSimilarOffers OffersOffer[] diff --git a/apps/portal/src/mappers/offers-mappers.ts b/apps/portal/src/mappers/offers-mappers.ts index 504e9400..07b37bb0 100644 --- a/apps/portal/src/mappers/offers-mappers.ts +++ b/apps/portal/src/mappers/offers-mappers.ts @@ -126,6 +126,7 @@ const analysisOfferDtoMapper = ( const analysisUnitDtoMapper = ( analysisUnit: OffersAnalysisUnit & { + company: Company; topSimilarOffers: Array< OffersOffer & { company: Company; @@ -153,7 +154,7 @@ const analysisUnitDtoMapper = ( }, ) => { const analysisDto: AnalysisUnit = { - companyName: analysisUnit.companyName, + companyName: analysisUnit.company.name, noOfOffers: analysisUnit.noOfSimilarOffers, percentile: analysisUnit.percentile, topPercentileOffers: analysisUnit.topSimilarOffers.map((offer) => @@ -189,6 +190,7 @@ export const profileAnalysisDtoMapper = ( | (OffersAnalysis & { companyAnalysis: Array< OffersAnalysisUnit & { + company: Company; topSimilarOffers: Array< OffersOffer & { company: Company; @@ -218,6 +220,7 @@ export const profileAnalysisDtoMapper = ( } >; overallAnalysis: OffersAnalysisUnit & { + company: Company; topSimilarOffers: Array< OffersOffer & { company: Company; @@ -501,6 +504,7 @@ export const profileDtoMapper = ( | (OffersAnalysis & { companyAnalysis: Array< OffersAnalysisUnit & { + company: Company; topSimilarOffers: Array< OffersOffer & { company: Company; @@ -532,6 +536,7 @@ export const profileDtoMapper = ( } >; overallAnalysis: OffersAnalysisUnit & { + company: Company; topSimilarOffers: Array< OffersOffer & { company: Company; diff --git a/apps/portal/src/server/router/offers/offers-analysis-router.ts b/apps/portal/src/server/router/offers/offers-analysis-router.ts index 06e8db8c..5fdd9062 100644 --- a/apps/portal/src/server/router/offers/offers-analysis-router.ts +++ b/apps/portal/src/server/router/offers/offers-analysis-router.ts @@ -16,6 +16,7 @@ export const offersAnalysisRouter = createRouter() include: { companyAnalysis: { include: { + company: true, topSimilarOffers: { include: { company: true, @@ -66,6 +67,7 @@ export const offersAnalysisRouter = createRouter() }, overallAnalysis: { include: { + company: true, topSimilarOffers: { include: { company: true, 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 43f51840..39cd0d4f 100644 --- a/apps/portal/src/server/router/offers/offers-profile-router.ts +++ b/apps/portal/src/server/router/offers/offers-profile-router.ts @@ -168,6 +168,7 @@ export const offersProfileRouter = createRouter() include: { companyAnalysis: { include: { + company: true, topSimilarOffers: { include: { company: true, @@ -218,6 +219,7 @@ export const offersProfileRouter = createRouter() }, overallAnalysis: { include: { + company: true, topSimilarOffers: { include: { company: true, @@ -425,8 +427,8 @@ export const offersProfileRouter = createRouter() level: x.level, location: { connect: { - id: x.cityId - } + id: x.cityId, + }, }, title: x.title, totalCompensation: @@ -481,9 +483,9 @@ export const offersProfileRouter = createRouter() location: { connect: { where: { - id: x.cityId - } - } + id: x.cityId, + }, + }, }, title: x.title, totalCompensation: @@ -539,9 +541,9 @@ export const offersProfileRouter = createRouter() location: { connect: { where: { - id: x.cityId - } - } + id: x.cityId, + }, + }, }, monthlySalary: x.monthlySalary != null @@ -595,9 +597,9 @@ export const offersProfileRouter = createRouter() location: { connect: { where: { - id: x.cityId - } - } + id: x.cityId, + }, + }, }, monthlySalary: x.monthlySalary != null @@ -680,8 +682,8 @@ export const offersProfileRouter = createRouter() jobType: x.jobType, location: { connect: { - id: x.cityId - } + id: x.cityId, + }, }, monthYearReceived: x.monthYearReceived, negotiationStrategy: x.negotiationStrategy, @@ -724,8 +726,8 @@ export const offersProfileRouter = createRouter() jobType: x.jobType, location: { connect: { - id: x.cityId - } + id: x.cityId, + }, }, monthYearReceived: x.monthYearReceived, negotiationStrategy: x.negotiationStrategy, @@ -1074,8 +1076,8 @@ export const offersProfileRouter = createRouter() level: exp.level, location: { connect: { - id: exp.cityId - } + id: exp.cityId, + }, }, title: exp.title, totalCompensation: exp.totalCompensation @@ -1145,8 +1147,8 @@ export const offersProfileRouter = createRouter() level: exp.level, location: { connect: { - id: exp.cityId - } + id: exp.cityId, + }, }, title: exp.title, totalCompensation: { @@ -1213,8 +1215,8 @@ export const offersProfileRouter = createRouter() level: exp.level, location: { connect: { - id: exp.cityId - } + id: exp.cityId, + }, }, title: exp.title, }, @@ -1256,8 +1258,8 @@ export const offersProfileRouter = createRouter() level: exp.level, location: { connect: { - id: exp.cityId - } + id: exp.cityId, + }, }, title: exp.title, }, @@ -1305,8 +1307,8 @@ export const offersProfileRouter = createRouter() jobType: exp.jobType, location: { connect: { - id: exp.cityId - } + id: exp.cityId, + }, }, monthlySalary: { create: { @@ -1370,8 +1372,8 @@ export const offersProfileRouter = createRouter() jobType: exp.jobType, location: { connect: { - id: exp.cityId - } + id: exp.cityId, + }, }, monthlySalary: { create: { @@ -1437,7 +1439,7 @@ export const offersProfileRouter = createRouter() location: { connect: { id: exp.cityId, - } + }, }, title: exp.title, }, @@ -1477,8 +1479,8 @@ export const offersProfileRouter = createRouter() jobType: exp.jobType, location: { connect: { - id: exp.cityId - } + id: exp.cityId, + }, }, title: exp.title, }, @@ -1584,8 +1586,8 @@ export const offersProfileRouter = createRouter() comments: offerToUpdate.comments, company: { connect: { - id: offerToUpdate.companyId - } + id: offerToUpdate.companyId, + }, }, jobType: offerToUpdate.jobType === JobType.FULLTIME @@ -1593,8 +1595,8 @@ export const offersProfileRouter = createRouter() : JobType.INTERN, location: { connect: { - id: offerToUpdate.cityId - } + id: offerToUpdate.cityId, + }, }, monthYearReceived: offerToUpdate.monthYearReceived, negotiationStrategy: offerToUpdate.negotiationStrategy, @@ -1820,8 +1822,8 @@ export const offersProfileRouter = createRouter() jobType: offerToUpdate.jobType, location: { connect: { - id: offerToUpdate.cityId - } + id: offerToUpdate.cityId, + }, }, monthYearReceived: offerToUpdate.monthYearReceived, negotiationStrategy: offerToUpdate.negotiationStrategy, @@ -1878,8 +1880,8 @@ export const offersProfileRouter = createRouter() jobType: offerToUpdate.jobType, location: { connect: { - id: offerToUpdate.cityId - } + id: offerToUpdate.cityId, + }, }, monthYearReceived: offerToUpdate.monthYearReceived, negotiationStrategy: offerToUpdate.negotiationStrategy, diff --git a/apps/portal/src/utils/offers/analysisGeneration.ts b/apps/portal/src/utils/offers/analysisGeneration.ts index a2594079..ad0fb428 100644 --- a/apps/portal/src/utils/offers/analysisGeneration.ts +++ b/apps/portal/src/utils/offers/analysisGeneration.ts @@ -292,7 +292,7 @@ export const generateAnalysis = async (params: { : similarCompanyOffers; return { - companyName: companyOffer.company.name, + companyId: companyOffer.companyId, noOfSimilarOffers: noOfSimilarCompanyOffers, percentile: companyPercentile, topSimilarOffers: topPercentileCompanyOffers, @@ -329,7 +329,11 @@ export const generateAnalysis = async (params: { companyAnalysis: { create: companyAnalysis.map((analysisUnit) => { return { - companyName: analysisUnit.companyName, + company: { + connect: { + id: analysisUnit.companyId, + }, + }, noOfSimilarOffers: analysisUnit.noOfSimilarOffers, percentile: analysisUnit.percentile, topSimilarOffers: { @@ -342,7 +346,11 @@ export const generateAnalysis = async (params: { }, overallAnalysis: { create: { - companyName: overallHighestOffer.company.name, + company: { + connect: { + id: overallHighestOffer.companyId, + }, + }, noOfSimilarOffers, percentile: overallPercentile, topSimilarOffers: { @@ -366,6 +374,7 @@ export const generateAnalysis = async (params: { include: { companyAnalysis: { include: { + company: true, topSimilarOffers: { include: { company: true, @@ -416,6 +425,7 @@ export const generateAnalysis = async (params: { }, overallAnalysis: { include: { + company: true, topSimilarOffers: { include: { company: true,