[offers][chore] Add reference to analysed offer in analysis unit (#504)

Co-authored-by: Bryann Yeap Kok Keong <bryannyeapkk@gmail.com>
pull/511/head
Bryann Yeap Kok Keong 2 years ago committed by GitHub
parent a7b4daec21
commit 80fd274662
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,16 @@
/*
Warnings:
- You are about to drop the column `companyId` on the `OffersAnalysisUnit` table. All the data in the column will be lost.
- Added the required column `analysedOfferId` to the `OffersAnalysisUnit` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE "OffersAnalysisUnit" DROP CONSTRAINT "OffersAnalysisUnit_companyId_fkey";
-- AlterTable
ALTER TABLE "OffersAnalysisUnit" DROP COLUMN "companyId",
ADD COLUMN "analysedOfferId" TEXT NOT NULL;
-- AddForeignKey
ALTER TABLE "OffersAnalysisUnit" ADD CONSTRAINT "OffersAnalysisUnit_analysedOfferId_fkey" FOREIGN KEY ("analysedOfferId") REFERENCES "OffersOffer"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

@ -104,7 +104,6 @@ model Company {
questionsQuestionEncounter QuestionsQuestionEncounter[]
OffersExperience OffersExperience[]
OffersOffer OffersOffer[]
OffersAnalysisUnit OffersAnalysisUnit[]
}
model Country {
@ -368,6 +367,7 @@ model OffersOffer {
offersAnalysis OffersAnalysis? @relation("HighestOverallOffer")
offersAnalysisUnit OffersAnalysisUnit[]
OffersAnalysisUnit OffersAnalysisUnit[] @relation("Analysed Offer")
}
model OffersIntern {
@ -419,8 +419,8 @@ model OffersAnalysis {
model OffersAnalysisUnit {
id String @id @default(cuid())
company Company @relation(fields: [companyId], references: [id])
companyId String
analysedOffer OffersOffer @relation("Analysed Offer", fields: [analysedOfferId], references: [id])
analysedOfferId String
percentile Float
noOfSimilarOffers Int

@ -133,7 +133,14 @@ const analysisOfferDtoMapper = (
const analysisUnitDtoMapper = (
analysisUnit: OffersAnalysisUnit & {
analysedOffer: OffersOffer & {
company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency })
| null;
offersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null;
profile: OffersProfile & { background: OffersBackground | null };
};
topSimilarOffers: Array<
OffersOffer & {
company: Company;
@ -161,7 +168,7 @@ const analysisUnitDtoMapper = (
},
) => {
const analysisDto: AnalysisUnit = {
companyName: analysisUnit.company.name,
companyName: analysisUnit.analysedOffer.company.name,
noOfOffers: analysisUnit.noOfSimilarOffers,
percentile: analysisUnit.percentile,
topPercentileOffers: analysisUnit.topSimilarOffers.map((offer) =>
@ -197,7 +204,16 @@ export const profileAnalysisDtoMapper = (
| (OffersAnalysis & {
companyAnalysis: Array<
OffersAnalysisUnit & {
analysedOffer: OffersOffer & {
company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency })
| null;
offersIntern:
| (OffersIntern & { monthlySalary: OffersCurrency })
| null;
profile: OffersProfile & { background: OffersBackground | null };
};
topSimilarOffers: Array<
OffersOffer & {
company: Company;
@ -227,7 +243,16 @@ export const profileAnalysisDtoMapper = (
}
>;
overallAnalysis: OffersAnalysisUnit & {
analysedOffer: OffersOffer & {
company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency })
| null;
offersIntern:
| (OffersIntern & { monthlySalary: OffersCurrency })
| null;
profile: OffersProfile & { background: OffersBackground | null };
};
topSimilarOffers: Array<
OffersOffer & {
company: Company;
@ -513,7 +538,18 @@ export const profileDtoMapper = (
| (OffersAnalysis & {
companyAnalysis: Array<
OffersAnalysisUnit & {
analysedOffer: OffersOffer & {
company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency })
| null;
offersIntern:
| (OffersIntern & { monthlySalary: OffersCurrency })
| null;
profile: OffersProfile & {
background: OffersBackground | null;
};
};
topSimilarOffers: Array<
OffersOffer & {
company: Company;
@ -545,7 +581,16 @@ export const profileDtoMapper = (
}
>;
overallAnalysis: OffersAnalysisUnit & {
analysedOffer: OffersOffer & {
company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency })
| null;
offersIntern:
| (OffersIntern & { monthlySalary: OffersCurrency })
| null;
profile: OffersProfile & { background: OffersBackground | null };
};
topSimilarOffers: Array<
OffersOffer & {
company: Company;

@ -2,9 +2,10 @@ import { z } from 'zod';
import { TRPCError } from '@trpc/server';
import { profileAnalysisDtoMapper } from '~/mappers/offers-mappers';
import { analysisInclusion } from '~/utils/offers/analysis/analysisInclusion';
import { createRouter } from '../context';
import { generateAnalysis } from '../../../utils/offers/analysisGeneration';
import { generateAnalysis } from '../../../utils/offers/analysis/analysisGeneration';
export const offersAnalysisRouter = createRouter()
.query('get', {
@ -13,139 +14,7 @@ export const offersAnalysisRouter = createRouter()
}),
async resolve({ ctx, input }) {
const analysis = await ctx.prisma.offersAnalysis.findFirst({
include: {
companyAnalysis: {
include: {
company: true,
topSimilarOffers: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: {
include: {
experiences: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
},
},
},
},
},
},
},
},
},
},
overallAnalysis: {
include: {
company: true,
topSimilarOffers: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: {
include: {
experiences: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
},
},
},
},
},
},
},
},
},
},
overallHighestOffer: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: true,
},
},
},
},
},
include: analysisInclusion,
where: {
profileId: input.profileId,
},

@ -8,6 +8,7 @@ import {
createOfferProfileResponseMapper,
profileDtoMapper,
} from '~/mappers/offers-mappers';
import { analysisInclusion } from '~/utils/offers/analysis/analysisInclusion';
import { baseCurrencyString } from '~/utils/offers/currency';
import { convert } from '~/utils/offers/currency/currencyExchange';
import {
@ -165,139 +166,7 @@ export const offersProfileRouter = createRouter()
const result = await ctx.prisma.offersProfile.findFirst({
include: {
analysis: {
include: {
companyAnalysis: {
include: {
company: true,
topSimilarOffers: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: {
include: {
experiences: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
},
},
},
},
},
},
},
},
},
},
overallAnalysis: {
include: {
company: true,
topSimilarOffers: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: {
include: {
experiences: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
},
},
},
},
},
},
},
},
},
},
overallHighestOffer: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: true,
},
},
},
},
},
include: analysisInclusion,
},
background: {
include: {
@ -974,9 +843,9 @@ export const offersProfileRouter = createRouter()
if (exp.id) {
const currentExp = await ctx.prisma.offersExperience.findFirst({
where: {
id: exp.id
}
})
id: exp.id,
},
});
if (!currentExp) {
throw new trpc.TRPCError({
@ -1107,9 +976,9 @@ export const offersProfileRouter = createRouter()
totalCompensationId: null,
},
where: {
id: exp.id
}
})
id: exp.id,
},
});
} else if (exp.jobType === JobType.FULLTIME) {
if (exp.totalCompensation) {
await ctx.prisma.offersExperience.update({
@ -1148,12 +1017,12 @@ export const offersProfileRouter = createRouter()
await ctx.prisma.offersExperience.update({
data: {
monthlySalary: undefined,
monthlySalaryId: null
monthlySalaryId: null,
},
where: {
id: exp.id
}
})
id: exp.id,
},
});
}
} else if (!exp.id) {
// Create new experience
@ -1686,9 +1555,9 @@ export const offersProfileRouter = createRouter()
// Update existing offer
const currentOffer = await ctx.prisma.offersOffer.findFirst({
where: {
id: offerToUpdate.id
}
})
id: offerToUpdate.id,
},
});
if (!currentOffer) {
throw new trpc.TRPCError({
@ -1753,7 +1622,8 @@ export const offersProfileRouter = createRouter()
},
},
},
startYear: offerToUpdate.offersIntern.startYear ?? undefined,
startYear:
offerToUpdate.offersIntern.startYear ?? undefined,
title: offerToUpdate.offersIntern.title,
},
where: {
@ -1786,7 +1656,8 @@ export const offersProfileRouter = createRouter()
),
currency:
offerToUpdate.offersFullTime.baseSalary.currency,
value: offerToUpdate.offersFullTime.baseSalary.value,
value:
offerToUpdate.offersFullTime.baseSalary.value,
},
update: {
baseCurrency: baseCurrencyString,
@ -1797,7 +1668,8 @@ export const offersProfileRouter = createRouter()
),
currency:
offerToUpdate.offersFullTime.baseSalary.currency,
value: offerToUpdate.offersFullTime.baseSalary.value,
value:
offerToUpdate.offersFullTime.baseSalary.value,
},
},
},
@ -1819,7 +1691,8 @@ export const offersProfileRouter = createRouter()
offerToUpdate.offersFullTime.bonus.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersFullTime.bonus.currency,
currency:
offerToUpdate.offersFullTime.bonus.currency,
value: offerToUpdate.offersFullTime.bonus.value,
},
update: {
@ -1829,7 +1702,8 @@ export const offersProfileRouter = createRouter()
offerToUpdate.offersFullTime.bonus.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersFullTime.bonus.currency,
currency:
offerToUpdate.offersFullTime.bonus.currency,
value: offerToUpdate.offersFullTime.bonus.value,
},
},
@ -1882,7 +1756,8 @@ export const offersProfileRouter = createRouter()
create: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
offerToUpdate.offersFullTime.totalCompensation.value,
offerToUpdate.offersFullTime.totalCompensation
.value,
offerToUpdate.offersFullTime.totalCompensation
.currency,
baseCurrencyString,
@ -1891,12 +1766,14 @@ export const offersProfileRouter = createRouter()
offerToUpdate.offersFullTime.totalCompensation
.currency,
value:
offerToUpdate.offersFullTime.totalCompensation.value,
offerToUpdate.offersFullTime.totalCompensation
.value,
},
update: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
offerToUpdate.offersFullTime.totalCompensation.value,
offerToUpdate.offersFullTime.totalCompensation
.value,
offerToUpdate.offersFullTime.totalCompensation
.currency,
baseCurrencyString,
@ -1905,7 +1782,8 @@ export const offersProfileRouter = createRouter()
offerToUpdate.offersFullTime.totalCompensation
.currency,
value:
offerToUpdate.offersFullTime.totalCompensation.value,
offerToUpdate.offersFullTime.totalCompensation
.value,
},
},
},
@ -1940,7 +1818,8 @@ export const offersProfileRouter = createRouter()
),
currency:
offerToUpdate.offersFullTime.baseSalary.currency,
value: offerToUpdate.offersFullTime.baseSalary.value,
value:
offerToUpdate.offersFullTime.baseSalary.value,
},
update: {
baseCurrency: baseCurrencyString,
@ -1951,7 +1830,8 @@ export const offersProfileRouter = createRouter()
),
currency:
offerToUpdate.offersFullTime.baseSalary.currency,
value: offerToUpdate.offersFullTime.baseSalary.value,
value:
offerToUpdate.offersFullTime.baseSalary.value,
},
},
},
@ -1973,7 +1853,8 @@ export const offersProfileRouter = createRouter()
offerToUpdate.offersFullTime.bonus.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersFullTime.bonus.currency,
currency:
offerToUpdate.offersFullTime.bonus.currency,
value: offerToUpdate.offersFullTime.bonus.value,
},
update: {
@ -1983,7 +1864,8 @@ export const offersProfileRouter = createRouter()
offerToUpdate.offersFullTime.bonus.currency,
baseCurrencyString,
),
currency: offerToUpdate.offersFullTime.bonus.currency,
currency:
offerToUpdate.offersFullTime.bonus.currency,
value: offerToUpdate.offersFullTime.bonus.value,
},
},
@ -2036,7 +1918,8 @@ export const offersProfileRouter = createRouter()
create: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
offerToUpdate.offersFullTime.totalCompensation.value,
offerToUpdate.offersFullTime.totalCompensation
.value,
offerToUpdate.offersFullTime.totalCompensation
.currency,
baseCurrencyString,
@ -2045,12 +1928,14 @@ export const offersProfileRouter = createRouter()
offerToUpdate.offersFullTime.totalCompensation
.currency,
value:
offerToUpdate.offersFullTime.totalCompensation.value,
offerToUpdate.offersFullTime.totalCompensation
.value,
},
update: {
baseCurrency: baseCurrencyString,
baseValue: await convert(
offerToUpdate.offersFullTime.totalCompensation.value,
offerToUpdate.offersFullTime.totalCompensation
.value,
offerToUpdate.offersFullTime.totalCompensation
.currency,
baseCurrencyString,
@ -2059,7 +1944,8 @@ export const offersProfileRouter = createRouter()
offerToUpdate.offersFullTime.totalCompensation
.currency,
value:
offerToUpdate.offersFullTime.totalCompensation.value,
offerToUpdate.offersFullTime.totalCompensation
.value,
},
},
},
@ -2073,12 +1959,12 @@ export const offersProfileRouter = createRouter()
await ctx.prisma.offersOffer.update({
data: {
offersIntern: undefined,
offersInternId: null
offersInternId: null,
},
where: {
id: offerToUpdate.id
}
})
id: offerToUpdate.id,
},
});
} else if (currentOffer.jobType === JobType.INTERN) {
if (offerToUpdate.offersIntern?.monthlySalary != null) {
await ctx.prisma.offersIntern.update({
@ -2111,7 +1997,8 @@ export const offersProfileRouter = createRouter()
},
},
},
startYear: offerToUpdate.offersIntern.startYear ?? undefined,
startYear:
offerToUpdate.offersIntern.startYear ?? undefined,
title: offerToUpdate.offersIntern.title,
},
where: {
@ -2123,12 +2010,12 @@ export const offersProfileRouter = createRouter()
await ctx.prisma.offersOffer.update({
data: {
offersFullTime: undefined,
offersFullTimeId: null
offersFullTimeId: null,
},
where: {
id: offerToUpdate.id
}
})
id: offerToUpdate.id,
},
});
}
} else {
// Create new offer

@ -15,7 +15,8 @@ import type {
} from '@prisma/client';
import { TRPCError } from '@trpc/server';
import { profileAnalysisDtoMapper } from '../../mappers/offers-mappers';
import { analysisInclusion } from './analysisInclusion';
import { profileAnalysisDtoMapper } from '../../../mappers/offers-mappers';
type Offer = OffersOffer & {
company: Company;
@ -292,7 +293,7 @@ export const generateAnalysis = async (params: {
: similarCompanyOffers;
return {
companyId: companyOffer.companyId,
analysedOfferId: companyOffer.id,
noOfSimilarOffers: noOfSimilarCompanyOffers,
percentile: companyPercentile,
topSimilarOffers: topPercentileCompanyOffers,
@ -329,9 +330,9 @@ export const generateAnalysis = async (params: {
companyAnalysis: {
create: companyAnalysis.map((analysisUnit) => {
return {
company: {
analysedOffer: {
connect: {
id: analysisUnit.companyId,
id: analysisUnit.analysedOfferId,
},
},
noOfSimilarOffers: analysisUnit.noOfSimilarOffers,
@ -346,9 +347,9 @@ export const generateAnalysis = async (params: {
},
overallAnalysis: {
create: {
company: {
analysedOffer: {
connect: {
id: overallHighestOffer.companyId,
id: overallHighestOffer.id,
},
},
noOfSimilarOffers,
@ -371,139 +372,7 @@ export const generateAnalysis = async (params: {
},
},
},
include: {
companyAnalysis: {
include: {
company: true,
topSimilarOffers: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: {
include: {
experiences: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
},
},
},
},
},
},
},
},
},
},
overallAnalysis: {
include: {
company: true,
topSimilarOffers: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: {
include: {
experiences: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
},
},
},
},
},
},
},
},
},
},
overallHighestOffer: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: true,
},
},
},
},
},
include: analysisInclusion,
});
return profileAnalysisDtoMapper(analysis);

@ -0,0 +1,171 @@
export const analysisInclusion = {
companyAnalysis: {
include: {
analysedOffer: {
include: {
company: true,
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: true,
},
},
},
},
topSimilarOffers: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: {
include: {
experiences: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
},
},
},
},
},
},
},
},
},
},
overallAnalysis: {
include: {
analysedOffer: {
include: {
company: true,
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: true,
},
},
},
},
topSimilarOffers: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: {
include: {
experiences: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
},
},
},
},
},
},
},
},
},
},
overallHighestOffer: {
include: {
company: true,
location: {
include: {
state: {
include: {
country: true,
},
},
},
},
offersFullTime: {
include: {
totalCompensation: true,
},
},
offersIntern: {
include: {
monthlySalary: true,
},
},
profile: {
include: {
background: true,
},
},
},
},
};
Loading…
Cancel
Save