[offers][chore] add migration sql and change naming conventions

pull/396/head
Stuart Long Chay Boon 2 years ago
parent a53c10483e
commit a879639b53

@ -0,0 +1,14 @@
/*
Warnings:
- Made the column `totalYoe` on table `OffersBackground` required. This step will fail if there are existing NULL values in that column.
- Made the column `negotiationStrategy` on table `OffersOffer` required. This step will fail if there are existing NULL values in that column.
- Made the column `comments` on table `OffersOffer` required. This step will fail if there are existing NULL values in that column.
*/
-- AlterTable
ALTER TABLE "OffersBackground" ALTER COLUMN "totalYoe" SET NOT NULL;
-- AlterTable
ALTER TABLE "OffersOffer" ALTER COLUMN "negotiationStrategy" SET NOT NULL,
ALTER COLUMN "comments" SET NOT NULL;

@ -315,13 +315,13 @@ model OffersOffer {
jobType JobType jobType JobType
OffersIntern OffersIntern? @relation(fields: [offersInternId], references: [id], onDelete: Cascade) offersIntern OffersIntern? @relation(fields: [offersInternId], references: [id], onDelete: Cascade)
offersInternId String? @unique offersInternId String? @unique
OffersFullTime OffersFullTime? @relation(fields: [offersFullTimeId], references: [id], onDelete: Cascade) offersFullTime OffersFullTime? @relation(fields: [offersFullTimeId], references: [id], onDelete: Cascade)
offersFullTimeId String? @unique offersFullTimeId String? @unique
OffersAnalysis OffersAnalysis? @relation("HighestOverallOffer") OffersAnalysis OffersAnalysis? @relation("HighestOverallOffer")
OffersAnalysisTopOverallOffers OffersAnalysis[] @relation("TopOverallOffers") OffersAnalysisTopOverallOffers OffersAnalysis[] @relation("TopOverallOffers")
OffersAnalysisTopCompanyOffers OffersAnalysis[] @relation("TopCompanyOffers") OffersAnalysisTopCompanyOffers OffersAnalysis[] @relation("TopCompanyOffers")
} }

@ -37,11 +37,11 @@ import type {
const analysisOfferDtoMapper = ( const analysisOfferDtoMapper = (
offer: OffersOffer & { offer: OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency }) | (OffersFullTime & { totalCompensation: OffersCurrency })
| null; | null;
OffersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null; offersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null;
company: Company;
profile: OffersProfile & { background: OffersBackground | null }; profile: OffersProfile & { background: OffersBackground | null };
}, },
) => { ) => {
@ -51,7 +51,7 @@ const analysisOfferDtoMapper = (
id: offer.id, id: offer.id,
income: -1, income: -1,
jobType: offer.jobType, jobType: offer.jobType,
level: offer.OffersFullTime?.level ?? '', level: offer.offersFullTime?.level ?? '',
location: offer.location, location: offer.location,
monthYearReceived: offer.monthYearReceived, monthYearReceived: offer.monthYearReceived,
negotiationStrategy: offer.negotiationStrategy, negotiationStrategy: offer.negotiationStrategy,
@ -59,19 +59,19 @@ const analysisOfferDtoMapper = (
profileName, profileName,
specialization: specialization:
offer.jobType === JobType.FULLTIME offer.jobType === JobType.FULLTIME
? offer.OffersFullTime?.specialization ?? '' ? offer.offersFullTime?.specialization ?? ''
: offer.OffersIntern?.specialization ?? '', : offer.offersIntern?.specialization ?? '',
title: title:
offer.jobType === JobType.FULLTIME offer.jobType === JobType.FULLTIME
? offer.OffersFullTime?.title ?? '' ? offer.offersFullTime?.title ?? ''
: offer.OffersIntern?.title ?? '', : offer.offersIntern?.title ?? '',
totalYoe: background?.totalYoe ?? -1, totalYoe: background?.totalYoe ?? -1,
}; };
if (offer.OffersFullTime?.totalCompensation) { if (offer.offersFullTime?.totalCompensation) {
analysisOfferDto.income = offer.OffersFullTime.totalCompensation.value; analysisOfferDto.income = offer.offersFullTime.totalCompensation.value;
} else if (offer.OffersIntern?.monthlySalary) { } else if (offer.offersIntern?.monthlySalary) {
analysisOfferDto.income = offer.OffersIntern.monthlySalary.value; analysisOfferDto.income = offer.offersIntern.monthlySalary.value;
} }
return analysisOfferDto; return analysisOfferDto;
@ -82,11 +82,11 @@ const analysisDtoMapper = (
percentile: number, percentile: number,
topPercentileOffers: Array< topPercentileOffers: Array<
OffersOffer & { OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency }) | (OffersFullTime & { totalCompensation: OffersCurrency })
| null; | null;
OffersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null; offersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null;
company: Company;
profile: OffersProfile & { background: OffersBackground | null }; profile: OffersProfile & { background: OffersBackground | null };
} }
>, >,
@ -103,23 +103,23 @@ const analysisDtoMapper = (
const analysisHighestOfferDtoMapper = ( const analysisHighestOfferDtoMapper = (
offer: OffersOffer & { offer: OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency }) | (OffersFullTime & { totalCompensation: OffersCurrency })
| null; | null;
OffersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null; offersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null;
company: Company;
profile: OffersProfile & { background: OffersBackground | null }; profile: OffersProfile & { background: OffersBackground | null };
}, },
) => { ) => {
const analysisHighestOfferDto: AnalysisHighestOffer = { const analysisHighestOfferDto: AnalysisHighestOffer = {
company: offersCompanyDtoMapper(offer.company), company: offersCompanyDtoMapper(offer.company),
id: offer.id, id: offer.id,
level: offer.OffersFullTime?.level ?? '', level: offer.offersFullTime?.level ?? '',
location: offer.location, location: offer.location,
specialization: specialization:
offer.jobType === JobType.FULLTIME offer.jobType === JobType.FULLTIME
? offer.OffersFullTime?.specialization ?? '' ? offer.offersFullTime?.specialization ?? ''
: offer.OffersIntern?.specialization ?? '', : offer.offersIntern?.specialization ?? '',
totalYoe: offer.profile.background?.totalYoe ?? -1, totalYoe: offer.profile.background?.totalYoe ?? -1,
}; };
return analysisHighestOfferDto; return analysisHighestOfferDto;
@ -129,24 +129,24 @@ export const profileAnalysisDtoMapper = (
analysis: analysis:
| (OffersAnalysis & { | (OffersAnalysis & {
overallHighestOffer: OffersOffer & { overallHighestOffer: OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency }) | (OffersFullTime & { totalCompensation: OffersCurrency })
| null; | null;
OffersIntern: offersIntern:
| (OffersIntern & { monthlySalary: OffersCurrency }) | (OffersIntern & { monthlySalary: OffersCurrency })
| null; | null;
company: Company;
profile: OffersProfile & { background: OffersBackground | null }; profile: OffersProfile & { background: OffersBackground | null };
}; };
topCompanyOffers: Array< topCompanyOffers: Array<
OffersOffer & { OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency }) | (OffersFullTime & { totalCompensation: OffersCurrency })
| null; | null;
OffersIntern: offersIntern:
| (OffersIntern & { monthlySalary: OffersCurrency }) | (OffersIntern & { monthlySalary: OffersCurrency })
| null; | null;
company: Company;
profile: OffersProfile & { profile: OffersProfile & {
background: background:
| (OffersBackground & { | (OffersBackground & {
@ -160,13 +160,13 @@ export const profileAnalysisDtoMapper = (
>; >;
topOverallOffers: Array< topOverallOffers: Array<
OffersOffer & { OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency }) | (OffersFullTime & { totalCompensation: OffersCurrency })
| null; | null;
OffersIntern: offersIntern:
| (OffersIntern & { monthlySalary: OffersCurrency }) | (OffersIntern & { monthlySalary: OffersCurrency })
| null; | null;
company: Company;
profile: OffersProfile & { profile: OffersProfile & {
background: background:
| (OffersBackground & { | (OffersBackground & {
@ -337,7 +337,8 @@ export const backgroundDtoMapper = (
export const profileOfferDtoMapper = ( export const profileOfferDtoMapper = (
offer: OffersOffer & { offer: OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { | (OffersFullTime & {
baseSalary: OffersCurrency; baseSalary: OffersCurrency;
bonus: OffersCurrency; bonus: OffersCurrency;
@ -345,8 +346,7 @@ export const profileOfferDtoMapper = (
totalCompensation: OffersCurrency; totalCompensation: OffersCurrency;
}) })
| null; | null;
OffersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null; offersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null;
company: Company;
}, },
) => { ) => {
const profileOfferDto: ProfileOffer = { const profileOfferDto: ProfileOffer = {
@ -357,31 +357,31 @@ export const profileOfferDtoMapper = (
location: offer.location, location: offer.location,
monthYearReceived: offer.monthYearReceived, monthYearReceived: offer.monthYearReceived,
negotiationStrategy: offer.negotiationStrategy, negotiationStrategy: offer.negotiationStrategy,
offersFullTime: offer.OffersFullTime, offersFullTime: offer.offersFullTime,
offersIntern: offer.OffersIntern, offersIntern: offer.offersIntern,
}; };
if (offer.OffersFullTime) { if (offer.offersFullTime) {
profileOfferDto.offersFullTime = { profileOfferDto.offersFullTime = {
baseSalary: valuationDtoMapper(offer.OffersFullTime.baseSalary), baseSalary: valuationDtoMapper(offer.offersFullTime.baseSalary),
bonus: valuationDtoMapper(offer.OffersFullTime.bonus), bonus: valuationDtoMapper(offer.offersFullTime.bonus),
id: offer.OffersFullTime.id, id: offer.offersFullTime.id,
level: offer.OffersFullTime.level, level: offer.offersFullTime.level,
specialization: offer.OffersFullTime.specialization, specialization: offer.offersFullTime.specialization,
stocks: valuationDtoMapper(offer.OffersFullTime.stocks), stocks: valuationDtoMapper(offer.offersFullTime.stocks),
title: offer.OffersFullTime.title, title: offer.offersFullTime.title,
totalCompensation: valuationDtoMapper( totalCompensation: valuationDtoMapper(
offer.OffersFullTime.totalCompensation, offer.offersFullTime.totalCompensation,
), ),
}; };
} else if (offer.OffersIntern) { } else if (offer.offersIntern) {
profileOfferDto.offersIntern = { profileOfferDto.offersIntern = {
id: offer.OffersIntern.id, id: offer.offersIntern.id,
internshipCycle: offer.OffersIntern.internshipCycle, internshipCycle: offer.offersIntern.internshipCycle,
monthlySalary: valuationDtoMapper(offer.OffersIntern.monthlySalary), monthlySalary: valuationDtoMapper(offer.offersIntern.monthlySalary),
specialization: offer.OffersIntern.specialization, specialization: offer.offersIntern.specialization,
startYear: offer.OffersIntern.startYear, startYear: offer.offersIntern.startYear,
title: offer.OffersIntern.title, title: offer.offersIntern.title,
}; };
} }
@ -393,24 +393,24 @@ export const profileDtoMapper = (
analysis: analysis:
| (OffersAnalysis & { | (OffersAnalysis & {
overallHighestOffer: OffersOffer & { overallHighestOffer: OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency }) | (OffersFullTime & { totalCompensation: OffersCurrency })
| null; | null;
OffersIntern: offersIntern:
| (OffersIntern & { monthlySalary: OffersCurrency }) | (OffersIntern & { monthlySalary: OffersCurrency })
| null; | null;
company: Company;
profile: OffersProfile & { background: OffersBackground | null }; profile: OffersProfile & { background: OffersBackground | null };
}; };
topCompanyOffers: Array< topCompanyOffers: Array<
OffersOffer & { OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency }) | (OffersFullTime & { totalCompensation: OffersCurrency })
| null; | null;
OffersIntern: offersIntern:
| (OffersIntern & { monthlySalary: OffersCurrency }) | (OffersIntern & { monthlySalary: OffersCurrency })
| null; | null;
company: Company;
profile: OffersProfile & { profile: OffersProfile & {
background: background:
| (OffersBackground & { | (OffersBackground & {
@ -424,13 +424,13 @@ export const profileDtoMapper = (
>; >;
topOverallOffers: Array< topOverallOffers: Array<
OffersOffer & { OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { totalCompensation: OffersCurrency }) | (OffersFullTime & { totalCompensation: OffersCurrency })
| null; | null;
OffersIntern: offersIntern:
| (OffersIntern & { monthlySalary: OffersCurrency }) | (OffersIntern & { monthlySalary: OffersCurrency })
| null; | null;
company: Company;
profile: OffersProfile & { profile: OffersProfile & {
background: background:
| (OffersBackground & { | (OffersBackground & {
@ -466,7 +466,8 @@ export const profileDtoMapper = (
>; >;
offers: Array< offers: Array<
OffersOffer & { OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { | (OffersFullTime & {
baseSalary: OffersCurrency; baseSalary: OffersCurrency;
bonus: OffersCurrency; bonus: OffersCurrency;
@ -474,8 +475,7 @@ export const profileDtoMapper = (
totalCompensation: OffersCurrency; totalCompensation: OffersCurrency;
}) })
| null; | null;
OffersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null; offersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null;
company: Company;
} }
>; >;
}, },
@ -526,7 +526,8 @@ export const addToProfileResponseMapper = (updatedProfile: {
export const dashboardOfferDtoMapper = ( export const dashboardOfferDtoMapper = (
offer: OffersOffer & { offer: OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { | (OffersFullTime & {
baseSalary: OffersCurrency; baseSalary: OffersCurrency;
bonus: OffersCurrency; bonus: OffersCurrency;
@ -534,8 +535,7 @@ export const dashboardOfferDtoMapper = (
totalCompensation: OffersCurrency; totalCompensation: OffersCurrency;
}) })
| null; | null;
OffersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null; offersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null;
company: Company;
profile: OffersProfile & { background: OffersBackground | null }; profile: OffersProfile & { background: OffersBackground | null };
}, },
) => { ) => {
@ -545,17 +545,17 @@ export const dashboardOfferDtoMapper = (
income: valuationDtoMapper({ currency: '', value: -1 }), income: valuationDtoMapper({ currency: '', value: -1 }),
monthYearReceived: offer.monthYearReceived, monthYearReceived: offer.monthYearReceived,
profileId: offer.profileId, profileId: offer.profileId,
title: offer.OffersFullTime?.title ?? '', title: offer.offersFullTime?.title ?? '',
totalYoe: offer.profile.background?.totalYoe ?? -1, totalYoe: offer.profile.background?.totalYoe ?? -1,
}; };
if (offer.OffersFullTime) { if (offer.offersFullTime) {
dashboardOfferDto.income = valuationDtoMapper( dashboardOfferDto.income = valuationDtoMapper(
offer.OffersFullTime.totalCompensation, offer.offersFullTime.totalCompensation,
); );
} else if (offer.OffersIntern) { } else if (offer.offersIntern) {
dashboardOfferDto.income = valuationDtoMapper( dashboardOfferDto.income = valuationDtoMapper(
offer.OffersIntern.monthlySalary, offer.offersIntern.monthlySalary,
); );
} }

@ -130,7 +130,14 @@ function Test() {
}, },
offers: [ offers: [
{ {
OffersFullTime: { comments: 'I am a Raffles Institution almumni',
// Comments: '',
companyId: 'cl98yuqk80007txhgjtjp8fk4',
jobType: 'FULLTIME',
location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'Leveraged having multiple offers',
offersFullTime: {
baseSalary: { baseSalary: {
currency: 'SGD', currency: 'SGD',
value: 84000, value: 84000,
@ -151,17 +158,15 @@ function Test() {
value: 104100, value: 104100,
}, },
}, },
},
comments: 'I am a Raffles Institution almumni', {
// Comments: '', comments: '',
companyId: 'cl98yuqk80007txhgjtjp8fk4', companyId: 'cl98yuqk80007txhgjtjp8fk4',
jobType: 'FULLTIME', jobType: 'FULLTIME',
location: 'Singapore, Singapore', location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'), monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'Leveraged having multiple offers', negotiationStrategy: 'Leveraged having multiple offers',
}, offersFullTime: {
{
OffersFullTime: {
baseSalary: { baseSalary: {
currency: 'SGD', currency: 'SGD',
value: 84000, value: 84000,
@ -182,12 +187,6 @@ function Test() {
value: 104100, value: 104100,
}, },
}, },
comments: '',
companyId: 'cl98yuqk80007txhgjtjp8fk4',
jobType: 'FULLTIME',
location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'Leveraged having multiple offers',
}, },
], ],
}); });
@ -330,7 +329,24 @@ function Test() {
isEditable: true, isEditable: true,
offers: [ offers: [
{ {
OffersFullTime: { comments: 'this IS SO IEUHDAEUIGDI',
company: {
createdAt: new Date('2022-10-12T16:19:05.196Z'),
description:
'Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.',
id: 'cl95u79f000007im531ysjg79',
logoUrl: 'https://logo.clearbit.com/meta.com',
name: 'Meta',
slug: 'meta',
updatedAt: new Date('2022-10-12T16:19:05.196Z'),
},
companyId: 'cl9ec1mgg0000w33hg1a3612r',
id: 'cl976t4de00047iygl0zbce11',
jobType: 'FULLTIME',
location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'Charmed the guy with my face',
offersFullTime: {
baseSalary: { baseSalary: {
currency: 'SGD', currency: 'SGD',
id: 'cl976t4de00067iyg3pjir7k9', id: 'cl976t4de00067iyg3pjir7k9',
@ -360,8 +376,13 @@ function Test() {
}, },
totalCompensationId: 'cl976t4df000c7iyg73ryf5uw', totalCompensationId: 'cl976t4df000c7iyg73ryf5uw',
}, },
OffersIntern: null, offersFullTimeId: 'cl976t4de00057iygq3ktce3v',
comments: 'this IS SO IEUHDAEUIGDI', offersIntern: null,
offersInternId: null,
profileId: 'cl96stky5002ew32gx2kale2x',
},
{
comments: '',
company: { company: {
createdAt: new Date('2022-10-12T16:19:05.196Z'), createdAt: new Date('2022-10-12T16:19:05.196Z'),
description: description:
@ -373,17 +394,12 @@ function Test() {
updatedAt: new Date('2022-10-12T16:19:05.196Z'), updatedAt: new Date('2022-10-12T16:19:05.196Z'),
}, },
companyId: 'cl9ec1mgg0000w33hg1a3612r', companyId: 'cl9ec1mgg0000w33hg1a3612r',
id: 'cl976t4de00047iygl0zbce11', id: 'cl96stky80031w32gau9mu1gs',
jobType: 'FULLTIME', jobType: 'FULLTIME',
location: 'Singapore, Singapore', location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'), monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'Charmed the guy with my face', negotiationStrategy: 'Leveraged having million offers',
offersFullTimeId: 'cl976t4de00057iygq3ktce3v', offersFullTime: {
offersInternId: null,
profileId: 'cl96stky5002ew32gx2kale2x',
},
{
OffersFullTime: {
baseSalary: { baseSalary: {
currency: 'SGD', currency: 'SGD',
id: 'cl96stky80033w32gxw5goc4z', id: 'cl96stky80033w32gxw5goc4z',
@ -413,7 +429,12 @@ function Test() {
}, },
totalCompensationId: 'cl96stky90039w32glbpktd0o', totalCompensationId: 'cl96stky90039w32glbpktd0o',
}, },
OffersIntern: null, offersFullTimeId: 'cl96stky80032w32gep9ovgj3',
offersIntern: null,
offersInternId: null,
profileId: 'cl96stky5002ew32gx2kale2x',
},
{
comments: '', comments: '',
company: { company: {
createdAt: new Date('2022-10-12T16:19:05.196Z'), createdAt: new Date('2022-10-12T16:19:05.196Z'),
@ -426,17 +447,12 @@ function Test() {
updatedAt: new Date('2022-10-12T16:19:05.196Z'), updatedAt: new Date('2022-10-12T16:19:05.196Z'),
}, },
companyId: 'cl9ec1mgg0000w33hg1a3612r', companyId: 'cl9ec1mgg0000w33hg1a3612r',
id: 'cl96stky80031w32gau9mu1gs', id: 'cl96stky9003bw32gc3l955vr',
jobType: 'FULLTIME', jobType: 'FULLTIME',
location: 'Singapore, Singapore', location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'), monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'Leveraged having million offers', negotiationStrategy: 'LOst out having multiple offers',
offersFullTimeId: 'cl96stky80032w32gep9ovgj3', offersFullTime: {
offersInternId: null,
profileId: 'cl96stky5002ew32gx2kale2x',
},
{
OffersFullTime: {
baseSalary: { baseSalary: {
currency: 'SGD', currency: 'SGD',
id: 'cl96stky9003dw32gcvqbijlo', id: 'cl96stky9003dw32gcvqbijlo',
@ -466,8 +482,13 @@ function Test() {
}, },
totalCompensationId: 'cl96stky9003jw32gzumcoi7v', totalCompensationId: 'cl96stky9003jw32gzumcoi7v',
}, },
OffersIntern: null, offersFullTimeId: 'cl96stky9003cw32g5v10izfu',
comments: '', offersIntern: null,
offersInternId: null,
profileId: 'cl96stky5002ew32gx2kale2x',
},
{
comments: 'this IS SO COOL',
company: { company: {
createdAt: new Date('2022-10-12T16:19:05.196Z'), createdAt: new Date('2022-10-12T16:19:05.196Z'),
description: description:
@ -479,17 +500,12 @@ function Test() {
updatedAt: new Date('2022-10-12T16:19:05.196Z'), updatedAt: new Date('2022-10-12T16:19:05.196Z'),
}, },
companyId: 'cl9ec1mgg0000w33hg1a3612r', companyId: 'cl9ec1mgg0000w33hg1a3612r',
id: 'cl96stky9003bw32gc3l955vr', id: 'cl976wf28000t7iyga4noyz7s',
jobType: 'FULLTIME', jobType: 'FULLTIME',
location: 'Singapore, Singapore', location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'), monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'LOst out having multiple offers', negotiationStrategy: 'Charmed the guy with my face',
offersFullTimeId: 'cl96stky9003cw32g5v10izfu', offersFullTime: {
offersInternId: null,
profileId: 'cl96stky5002ew32gx2kale2x',
},
{
OffersFullTime: {
baseSalary: { baseSalary: {
currency: 'SGD', currency: 'SGD',
id: 'cl976wf28000v7iygmk1b7qaq', id: 'cl976wf28000v7iygmk1b7qaq',
@ -519,8 +535,13 @@ function Test() {
}, },
totalCompensationId: 'cl976wf2800117iygmzsc0xit', totalCompensationId: 'cl976wf2800117iygmzsc0xit',
}, },
OffersIntern: null, offersFullTimeId: 'cl976wf28000u7iyg6euei8e9',
comments: 'this IS SO COOL', offersIntern: null,
offersInternId: null,
profileId: 'cl96stky5002ew32gx2kale2x',
},
{
comments: 'this rocks',
company: { company: {
createdAt: new Date('2022-10-12T16:19:05.196Z'), createdAt: new Date('2022-10-12T16:19:05.196Z'),
description: description:
@ -532,17 +553,12 @@ function Test() {
updatedAt: new Date('2022-10-12T16:19:05.196Z'), updatedAt: new Date('2022-10-12T16:19:05.196Z'),
}, },
companyId: 'cl9ec1mgg0000w33hg1a3612r', companyId: 'cl9ec1mgg0000w33hg1a3612r',
id: 'cl976wf28000t7iyga4noyz7s', id: 'cl96tbb3o0051w32gjrpaiiit',
jobType: 'FULLTIME', jobType: 'FULLTIME',
location: 'Singapore, Singapore', location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'), monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'Charmed the guy with my face', negotiationStrategy: 'Charmed the guy with my face',
offersFullTimeId: 'cl976wf28000u7iyg6euei8e9', offersFullTime: {
offersInternId: null,
profileId: 'cl96stky5002ew32gx2kale2x',
},
{
OffersFullTime: {
baseSalary: { baseSalary: {
currency: 'SGD', currency: 'SGD',
id: 'cl96tbb3o0053w32gz11paaxu', id: 'cl96tbb3o0053w32gz11paaxu',
@ -572,25 +588,8 @@ function Test() {
}, },
totalCompensationId: 'cl96tbb3o0059w32gm3iy1zk4', totalCompensationId: 'cl96tbb3o0059w32gm3iy1zk4',
}, },
OffersIntern: null,
comments: 'this rocks',
company: {
createdAt: new Date('2022-10-12T16:19:05.196Z'),
description:
'Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.',
id: 'cl95u79f000007im531ysjg79',
logoUrl: 'https://logo.clearbit.com/meta.com',
name: 'Meta',
slug: 'meta',
updatedAt: new Date('2022-10-12T16:19:05.196Z'),
},
companyId: 'cl9ec1mgg0000w33hg1a3612r',
id: 'cl96tbb3o0051w32gjrpaiiit',
jobType: 'FULLTIME',
location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'Charmed the guy with my face',
offersFullTimeId: 'cl96tbb3o0052w32guguajzin', offersFullTimeId: 'cl96tbb3o0052w32guguajzin',
offersIntern: null,
offersInternId: null, offersInternId: null,
profileId: 'cl96stky5002ew32gx2kale2x', profileId: 'cl96stky5002ew32gx2kale2x',
}, },

@ -16,7 +16,8 @@ import { createRouter } from '../context';
const searchOfferPercentile = ( const searchOfferPercentile = (
offer: OffersOffer & { offer: OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { | (OffersFullTime & {
baseSalary: OffersCurrency; baseSalary: OffersCurrency;
bonus: OffersCurrency; bonus: OffersCurrency;
@ -24,19 +25,18 @@ const searchOfferPercentile = (
totalCompensation: OffersCurrency; totalCompensation: OffersCurrency;
}) })
| null; | null;
OffersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null; offersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null;
company: Company;
profile: OffersProfile & { background: OffersBackground | null }; profile: OffersProfile & { background: OffersBackground | null };
}, },
similarOffers: Array< similarOffers: Array<
OffersOffer & { OffersOffer & {
OffersFullTime: company: Company;
offersFullTime:
| (OffersFullTime & { | (OffersFullTime & {
totalCompensation: OffersCurrency; totalCompensation: OffersCurrency;
}) })
| null; | null;
OffersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null; offersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null;
company: Company;
profile: OffersProfile & { background: OffersBackground | null }; profile: OffersProfile & { background: OffersBackground | null };
} }
>, >,
@ -64,7 +64,8 @@ export const offersAnalysisRouter = createRouter()
const offers = await ctx.prisma.offersOffer.findMany({ const offers = await ctx.prisma.offersOffer.findMany({
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
baseSalary: true, baseSalary: true,
bonus: true, bonus: true,
@ -72,12 +73,11 @@ export const offersAnalysisRouter = createRouter()
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
profile: { profile: {
include: { include: {
background: true, background: true,
@ -86,14 +86,14 @@ export const offersAnalysisRouter = createRouter()
}, },
orderBy: [ orderBy: [
{ {
OffersFullTime: { offersFullTime: {
totalCompensation: { totalCompensation: {
value: 'desc', value: 'desc',
}, },
}, },
}, },
{ {
OffersIntern: { offersIntern: {
monthlySalary: { monthlySalary: {
value: 'desc', value: 'desc',
}, },
@ -129,17 +129,17 @@ export const offersAnalysisRouter = createRouter()
let similarOffers = await ctx.prisma.offersOffer.findMany({ let similarOffers = await ctx.prisma.offersOffer.findMany({
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
profile: { profile: {
include: { include: {
background: { background: {
@ -156,14 +156,14 @@ export const offersAnalysisRouter = createRouter()
}, },
orderBy: [ orderBy: [
{ {
OffersFullTime: { offersFullTime: {
totalCompensation: { totalCompensation: {
value: 'desc', value: 'desc',
}, },
}, },
}, },
{ {
OffersIntern: { offersIntern: {
monthlySalary: { monthlySalary: {
value: 'desc', value: 'desc',
}, },
@ -178,14 +178,14 @@ export const offersAnalysisRouter = createRouter()
{ {
OR: [ OR: [
{ {
OffersFullTime: { offersFullTime: {
level: overallHighestOffer.OffersFullTime?.level, level: overallHighestOffer.offersFullTime?.level,
specialization: specialization:
overallHighestOffer.OffersFullTime?.specialization, overallHighestOffer.offersFullTime?.specialization,
}, },
OffersIntern: { offersIntern: {
specialization: specialization:
overallHighestOffer.OffersIntern?.specialization, overallHighestOffer.offersIntern?.specialization,
}, },
}, },
], ],
@ -289,17 +289,17 @@ export const offersAnalysisRouter = createRouter()
include: { include: {
overallHighestOffer: { overallHighestOffer: {
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
profile: { profile: {
include: { include: {
background: true, background: true,
@ -309,17 +309,17 @@ export const offersAnalysisRouter = createRouter()
}, },
topCompanyOffers: { topCompanyOffers: {
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
profile: { profile: {
include: { include: {
background: { background: {
@ -337,17 +337,17 @@ export const offersAnalysisRouter = createRouter()
}, },
topOverallOffers: { topOverallOffers: {
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
profile: { profile: {
include: { include: {
background: { background: {
@ -378,17 +378,17 @@ export const offersAnalysisRouter = createRouter()
include: { include: {
overallHighestOffer: { overallHighestOffer: {
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
profile: { profile: {
include: { include: {
background: true, background: true,
@ -398,17 +398,17 @@ export const offersAnalysisRouter = createRouter()
}, },
topCompanyOffers: { topCompanyOffers: {
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
profile: { profile: {
include: { include: {
background: { background: {
@ -426,17 +426,17 @@ export const offersAnalysisRouter = createRouter()
}, },
topOverallOffers: { topOverallOffers: {
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
profile: { profile: {
include: { include: {
background: { background: {

@ -27,7 +27,15 @@ const company = z.object({
}); });
const offer = z.object({ const offer = z.object({
OffersFullTime: z comments: z.string(),
company: company.nullish(),
companyId: z.string(),
id: z.string().optional(),
jobType: z.string(),
location: z.string(),
monthYearReceived: z.date(),
negotiationStrategy: z.string(),
offersFullTime: z
.object({ .object({
baseSalary: valuation.nullish(), baseSalary: valuation.nullish(),
baseSalaryId: z.string().nullish(), baseSalaryId: z.string().nullish(),
@ -43,7 +51,8 @@ const offer = z.object({
totalCompensationId: z.string().nullish(), totalCompensationId: z.string().nullish(),
}) })
.nullish(), .nullish(),
OffersIntern: z offersFullTimeId: z.string().nullish(),
offersIntern: z
.object({ .object({
id: z.string().optional(), id: z.string().optional(),
internshipCycle: z.string().nullish(), internshipCycle: z.string().nullish(),
@ -54,15 +63,6 @@ const offer = z.object({
totalCompensation: valuation.nullish(), // Full time totalCompensation: valuation.nullish(), // Full time
}) })
.nullish(), .nullish(),
comments: z.string(),
company: company.nullish(),
companyId: z.string(),
id: z.string().optional(),
jobType: z.string(),
location: z.string(),
monthYearReceived: z.date(),
negotiationStrategy: z.string(),
offersFullTimeId: z.string().nullish(),
offersInternId: z.string().nullish(), offersInternId: z.string().nullish(),
profileId: z.string().nullish(), profileId: z.string().nullish(),
}); });
@ -115,17 +115,17 @@ export const offersProfileRouter = createRouter()
include: { include: {
overallHighestOffer: { overallHighestOffer: {
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
profile: { profile: {
include: { include: {
background: true, background: true,
@ -135,17 +135,17 @@ export const offersProfileRouter = createRouter()
}, },
topCompanyOffers: { topCompanyOffers: {
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
profile: { profile: {
include: { include: {
background: { background: {
@ -163,17 +163,17 @@ export const offersProfileRouter = createRouter()
}, },
topOverallOffers: { topOverallOffers: {
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
profile: { profile: {
include: { include: {
background: { background: {
@ -213,7 +213,8 @@ export const offersProfileRouter = createRouter()
}, },
offers: { offers: {
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
baseSalary: true, baseSalary: true,
bonus: true, bonus: true,
@ -221,12 +222,11 @@ export const offersProfileRouter = createRouter()
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
}, },
}, },
}, },
@ -381,27 +381,53 @@ export const offersProfileRouter = createRouter()
create: input.offers.map((x) => { create: input.offers.map((x) => {
if ( if (
x.jobType === 'INTERN' && x.jobType === 'INTERN' &&
x.OffersIntern && x.offersIntern &&
x.OffersIntern.internshipCycle && x.offersIntern.internshipCycle &&
x.OffersIntern.monthlySalary?.currency && x.offersIntern.monthlySalary?.currency &&
x.OffersIntern.monthlySalary.value && x.offersIntern.monthlySalary.value &&
x.OffersIntern.startYear x.offersIntern.startYear
) { ) {
return { return {
OffersIntern: { comments: x.comments,
company: {
connect: {
id: x.companyId,
},
},
jobType: x.jobType,
location: x.location,
monthYearReceived: x.monthYearReceived,
negotiationStrategy: x.negotiationStrategy,
offersIntern: {
create: { create: {
internshipCycle: x.OffersIntern.internshipCycle, internshipCycle: x.offersIntern.internshipCycle,
monthlySalary: { monthlySalary: {
create: { create: {
currency: x.OffersIntern.monthlySalary?.currency, currency: x.offersIntern.monthlySalary?.currency,
value: x.OffersIntern.monthlySalary?.value, value: x.offersIntern.monthlySalary?.value,
}, },
}, },
specialization: x.OffersIntern.specialization, specialization: x.offersIntern.specialization,
startYear: x.OffersIntern.startYear, startYear: x.offersIntern.startYear,
title: x.OffersIntern.title, title: x.offersIntern.title,
}, },
}, },
};
}
if (
x.jobType === 'FULLTIME' &&
x.offersFullTime &&
x.offersFullTime.baseSalary?.currency &&
x.offersFullTime.baseSalary?.value &&
x.offersFullTime.bonus?.currency &&
x.offersFullTime.bonus?.value &&
x.offersFullTime.stocks?.currency &&
x.offersFullTime.stocks?.value &&
x.offersFullTime.totalCompensation?.currency &&
x.offersFullTime.totalCompensation?.value &&
x.offersFullTime.level
) {
return {
comments: x.comments, comments: x.comments,
company: { company: {
connect: { connect: {
@ -412,64 +438,38 @@ export const offersProfileRouter = createRouter()
location: x.location, location: x.location,
monthYearReceived: x.monthYearReceived, monthYearReceived: x.monthYearReceived,
negotiationStrategy: x.negotiationStrategy, negotiationStrategy: x.negotiationStrategy,
}; offersFullTime: {
}
if (
x.jobType === 'FULLTIME' &&
x.OffersFullTime &&
x.OffersFullTime.baseSalary?.currency &&
x.OffersFullTime.baseSalary?.value &&
x.OffersFullTime.bonus?.currency &&
x.OffersFullTime.bonus?.value &&
x.OffersFullTime.stocks?.currency &&
x.OffersFullTime.stocks?.value &&
x.OffersFullTime.totalCompensation?.currency &&
x.OffersFullTime.totalCompensation?.value &&
x.OffersFullTime.level
) {
return {
OffersFullTime: {
create: { create: {
baseSalary: { baseSalary: {
create: { create: {
currency: x.OffersFullTime.baseSalary?.currency, currency: x.offersFullTime.baseSalary?.currency,
value: x.OffersFullTime.baseSalary?.value, value: x.offersFullTime.baseSalary?.value,
}, },
}, },
bonus: { bonus: {
create: { create: {
currency: x.OffersFullTime.bonus?.currency, currency: x.offersFullTime.bonus?.currency,
value: x.OffersFullTime.bonus?.value, value: x.offersFullTime.bonus?.value,
}, },
}, },
level: x.OffersFullTime.level, level: x.offersFullTime.level,
specialization: x.OffersFullTime.specialization, specialization: x.offersFullTime.specialization,
stocks: { stocks: {
create: { create: {
currency: x.OffersFullTime.stocks?.currency, currency: x.offersFullTime.stocks?.currency,
value: x.OffersFullTime.stocks?.value, value: x.offersFullTime.stocks?.value,
}, },
}, },
title: x.OffersFullTime.title, title: x.offersFullTime.title,
totalCompensation: { totalCompensation: {
create: { create: {
currency: currency:
x.OffersFullTime.totalCompensation?.currency, x.offersFullTime.totalCompensation?.currency,
value: x.OffersFullTime.totalCompensation?.value, value: x.offersFullTime.totalCompensation?.value,
}, },
}, },
}, },
}, },
comments: x.comments,
company: {
connect: {
id: x.companyId,
},
},
jobType: x.jobType,
location: x.location,
monthYearReceived: x.monthYearReceived,
negotiationStrategy: x.negotiationStrategy,
}; };
} }
@ -813,127 +813,127 @@ export const offersProfileRouter = createRouter()
}); });
} }
if (offerToUpdate.OffersIntern?.monthlySalary) { if (offerToUpdate.offersIntern?.monthlySalary) {
await ctx.prisma.offersIntern.update({ await ctx.prisma.offersIntern.update({
data: { data: {
internshipCycle: internshipCycle:
offerToUpdate.OffersIntern.internshipCycle ?? undefined, offerToUpdate.offersIntern.internshipCycle ?? undefined,
specialization: offerToUpdate.OffersIntern.specialization, specialization: offerToUpdate.offersIntern.specialization,
startYear: offerToUpdate.OffersIntern.startYear ?? undefined, startYear: offerToUpdate.offersIntern.startYear ?? undefined,
title: offerToUpdate.OffersIntern.title, title: offerToUpdate.offersIntern.title,
}, },
where: { where: {
id: offerToUpdate.OffersIntern.id, id: offerToUpdate.offersIntern.id,
}, },
}); });
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersCurrency.update({
data: { data: {
currency: offerToUpdate.OffersIntern.monthlySalary.currency, currency: offerToUpdate.offersIntern.monthlySalary.currency,
value: offerToUpdate.OffersIntern.monthlySalary.value, value: offerToUpdate.offersIntern.monthlySalary.value,
}, },
where: { where: {
id: offerToUpdate.OffersIntern.monthlySalary.id, id: offerToUpdate.offersIntern.monthlySalary.id,
}, },
}); });
} }
if (offerToUpdate.OffersFullTime?.totalCompensation) { if (offerToUpdate.offersFullTime?.totalCompensation) {
await ctx.prisma.offersFullTime.update({ await ctx.prisma.offersFullTime.update({
data: { data: {
level: offerToUpdate.OffersFullTime.level ?? undefined, level: offerToUpdate.offersFullTime.level ?? undefined,
specialization: offerToUpdate.OffersFullTime.specialization, specialization: offerToUpdate.offersFullTime.specialization,
title: offerToUpdate.OffersFullTime.title, title: offerToUpdate.offersFullTime.title,
}, },
where: { where: {
id: offerToUpdate.OffersFullTime.id, id: offerToUpdate.offersFullTime.id,
}, },
}); });
if (offerToUpdate.OffersFullTime.baseSalary) { if (offerToUpdate.offersFullTime.baseSalary) {
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersCurrency.update({
data: { data: {
currency: offerToUpdate.OffersFullTime.baseSalary.currency, currency: offerToUpdate.offersFullTime.baseSalary.currency,
value: offerToUpdate.OffersFullTime.baseSalary.value, value: offerToUpdate.offersFullTime.baseSalary.value,
}, },
where: { where: {
id: offerToUpdate.OffersFullTime.baseSalary.id, id: offerToUpdate.offersFullTime.baseSalary.id,
}, },
}); });
} }
if (offerToUpdate.OffersFullTime.bonus) { if (offerToUpdate.offersFullTime.bonus) {
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersCurrency.update({
data: { data: {
currency: offerToUpdate.OffersFullTime.bonus.currency, currency: offerToUpdate.offersFullTime.bonus.currency,
value: offerToUpdate.OffersFullTime.bonus.value, value: offerToUpdate.offersFullTime.bonus.value,
}, },
where: { where: {
id: offerToUpdate.OffersFullTime.bonus.id, id: offerToUpdate.offersFullTime.bonus.id,
}, },
}); });
} }
if (offerToUpdate.OffersFullTime.stocks) { if (offerToUpdate.offersFullTime.stocks) {
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersCurrency.update({
data: { data: {
currency: offerToUpdate.OffersFullTime.stocks.currency, currency: offerToUpdate.offersFullTime.stocks.currency,
value: offerToUpdate.OffersFullTime.stocks.value, value: offerToUpdate.offersFullTime.stocks.value,
}, },
where: { where: {
id: offerToUpdate.OffersFullTime.stocks.id, id: offerToUpdate.offersFullTime.stocks.id,
}, },
}); });
} }
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersCurrency.update({
data: { data: {
currency: currency:
offerToUpdate.OffersFullTime.totalCompensation.currency, offerToUpdate.offersFullTime.totalCompensation.currency,
value: offerToUpdate.OffersFullTime.totalCompensation.value, value: offerToUpdate.offersFullTime.totalCompensation.value,
}, },
where: { where: {
id: offerToUpdate.OffersFullTime.totalCompensation.id, id: offerToUpdate.offersFullTime.totalCompensation.id,
}, },
}); });
} }
} else { } else {
if ( if (
offerToUpdate.jobType === 'INTERN' && offerToUpdate.jobType === 'INTERN' &&
offerToUpdate.OffersIntern && offerToUpdate.offersIntern &&
offerToUpdate.OffersIntern.internshipCycle && offerToUpdate.offersIntern.internshipCycle &&
offerToUpdate.OffersIntern.monthlySalary?.currency && offerToUpdate.offersIntern.monthlySalary?.currency &&
offerToUpdate.OffersIntern.monthlySalary.value && offerToUpdate.offersIntern.monthlySalary.value &&
offerToUpdate.OffersIntern.startYear offerToUpdate.offersIntern.startYear
) { ) {
await ctx.prisma.offersProfile.update({ await ctx.prisma.offersProfile.update({
data: { data: {
offers: { offers: {
create: { create: {
OffersIntern: { comments: offerToUpdate.comments,
company: {
connect: {
id: offerToUpdate.companyId,
},
},
jobType: offerToUpdate.jobType,
location: offerToUpdate.location,
monthYearReceived: offerToUpdate.monthYearReceived,
negotiationStrategy: offerToUpdate.negotiationStrategy,
offersIntern: {
create: { create: {
internshipCycle: internshipCycle:
offerToUpdate.OffersIntern.internshipCycle, offerToUpdate.offersIntern.internshipCycle,
monthlySalary: { monthlySalary: {
create: { create: {
currency: currency:
offerToUpdate.OffersIntern.monthlySalary offerToUpdate.offersIntern.monthlySalary
?.currency, ?.currency,
value: value:
offerToUpdate.OffersIntern.monthlySalary?.value, offerToUpdate.offersIntern.monthlySalary?.value,
}, },
}, },
specialization: specialization:
offerToUpdate.OffersIntern.specialization, offerToUpdate.offersIntern.specialization,
startYear: offerToUpdate.OffersIntern.startYear, startYear: offerToUpdate.offersIntern.startYear,
title: offerToUpdate.OffersIntern.title, title: offerToUpdate.offersIntern.title,
},
},
comments: offerToUpdate.comments,
company: {
connect: {
id: offerToUpdate.companyId,
}, },
}, },
jobType: offerToUpdate.jobType,
location: offerToUpdate.location,
monthYearReceived: offerToUpdate.monthYearReceived,
negotiationStrategy: offerToUpdate.negotiationStrategy,
}, },
}, },
}, },
@ -944,72 +944,72 @@ export const offersProfileRouter = createRouter()
} }
if ( if (
offerToUpdate.jobType === 'FULLTIME' && offerToUpdate.jobType === 'FULLTIME' &&
offerToUpdate.OffersFullTime && offerToUpdate.offersFullTime &&
offerToUpdate.OffersFullTime.baseSalary?.currency && offerToUpdate.offersFullTime.baseSalary?.currency &&
offerToUpdate.OffersFullTime.baseSalary?.value && offerToUpdate.offersFullTime.baseSalary?.value &&
offerToUpdate.OffersFullTime.bonus?.currency && offerToUpdate.offersFullTime.bonus?.currency &&
offerToUpdate.OffersFullTime.bonus?.value && offerToUpdate.offersFullTime.bonus?.value &&
offerToUpdate.OffersFullTime.stocks?.currency && offerToUpdate.offersFullTime.stocks?.currency &&
offerToUpdate.OffersFullTime.stocks?.value && offerToUpdate.offersFullTime.stocks?.value &&
offerToUpdate.OffersFullTime.totalCompensation?.currency && offerToUpdate.offersFullTime.totalCompensation?.currency &&
offerToUpdate.OffersFullTime.totalCompensation?.value && offerToUpdate.offersFullTime.totalCompensation?.value &&
offerToUpdate.OffersFullTime.level offerToUpdate.offersFullTime.level
) { ) {
await ctx.prisma.offersProfile.update({ await ctx.prisma.offersProfile.update({
data: { data: {
offers: { offers: {
create: { create: {
OffersFullTime: { comments: offerToUpdate.comments,
company: {
connect: {
id: offerToUpdate.companyId,
},
},
jobType: offerToUpdate.jobType,
location: offerToUpdate.location,
monthYearReceived: offerToUpdate.monthYearReceived,
negotiationStrategy: offerToUpdate.negotiationStrategy,
offersFullTime: {
create: { create: {
baseSalary: { baseSalary: {
create: { create: {
currency: currency:
offerToUpdate.OffersFullTime.baseSalary offerToUpdate.offersFullTime.baseSalary
?.currency, ?.currency,
value: value:
offerToUpdate.OffersFullTime.baseSalary?.value, offerToUpdate.offersFullTime.baseSalary?.value,
}, },
}, },
bonus: { bonus: {
create: { create: {
currency: currency:
offerToUpdate.OffersFullTime.bonus?.currency, offerToUpdate.offersFullTime.bonus?.currency,
value: offerToUpdate.OffersFullTime.bonus?.value, value: offerToUpdate.offersFullTime.bonus?.value,
}, },
}, },
level: offerToUpdate.OffersFullTime.level, level: offerToUpdate.offersFullTime.level,
specialization: specialization:
offerToUpdate.OffersFullTime.specialization, offerToUpdate.offersFullTime.specialization,
stocks: { stocks: {
create: { create: {
currency: currency:
offerToUpdate.OffersFullTime.stocks?.currency, offerToUpdate.offersFullTime.stocks?.currency,
value: offerToUpdate.OffersFullTime.stocks?.value, value: offerToUpdate.offersFullTime.stocks?.value,
}, },
}, },
title: offerToUpdate.OffersFullTime.title, title: offerToUpdate.offersFullTime.title,
totalCompensation: { totalCompensation: {
create: { create: {
currency: currency:
offerToUpdate.OffersFullTime.totalCompensation offerToUpdate.offersFullTime.totalCompensation
?.currency, ?.currency,
value: value:
offerToUpdate.OffersFullTime.totalCompensation offerToUpdate.offersFullTime.totalCompensation
?.value, ?.value,
}, },
}, },
}, },
}, },
comments: offerToUpdate.comments,
company: {
connect: {
id: offerToUpdate.companyId,
},
},
jobType: offerToUpdate.jobType,
location: offerToUpdate.location,
monthYearReceived: offerToUpdate.monthYearReceived,
negotiationStrategy: offerToUpdate.negotiationStrategy,
}, },
}, },
}, },
@ -1045,7 +1045,8 @@ export const offersProfileRouter = createRouter()
}, },
offers: { offers: {
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
baseSalary: true, baseSalary: true,
bonus: true, bonus: true,
@ -1053,12 +1054,11 @@ export const offersProfileRouter = createRouter()
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
}, },
}, },
}, },

@ -60,7 +60,8 @@ export const offersRouter = createRouter().query('list', {
? await ctx.prisma.offersOffer.findMany({ ? await ctx.prisma.offersOffer.findMany({
// Internship // Internship
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
baseSalary: true, baseSalary: true,
bonus: true, bonus: true,
@ -68,12 +69,11 @@ export const offersRouter = createRouter().query('list', {
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
profile: { profile: {
include: { include: {
background: true, background: true,
@ -86,12 +86,12 @@ export const offersRouter = createRouter().query('list', {
location: input.location, location: input.location,
}, },
{ {
OffersIntern: { offersIntern: {
isNot: null, isNot: null,
}, },
}, },
{ {
OffersFullTime: { offersFullTime: {
is: null, is: null,
}, },
}, },
@ -101,7 +101,8 @@ export const offersRouter = createRouter().query('list', {
: await ctx.prisma.offersOffer.findMany({ : await ctx.prisma.offersOffer.findMany({
// Junior, Mid, Senior // Junior, Mid, Senior
include: { include: {
OffersFullTime: { company: true,
offersFullTime: {
include: { include: {
baseSalary: true, baseSalary: true,
bonus: true, bonus: true,
@ -109,12 +110,11 @@ export const offersRouter = createRouter().query('list', {
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { offersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
}, },
company: true,
profile: { profile: {
include: { include: {
background: true, background: true,
@ -127,12 +127,12 @@ export const offersRouter = createRouter().query('list', {
location: input.location, location: input.location,
}, },
{ {
OffersIntern: { offersIntern: {
is: null, is: null,
}, },
}, },
{ {
OffersFullTime: { offersFullTime: {
isNot: null, isNot: null,
}, },
}, },
@ -161,8 +161,8 @@ export const offersRouter = createRouter().query('list', {
if (input.title) { if (input.title) {
validRecord = validRecord =
validRecord && validRecord &&
(offer.OffersFullTime?.title === input.title || (offer.offersFullTime?.title === input.title ||
offer.OffersIntern?.title === input.title); offer.offersIntern?.title === input.title);
} }
if (input.dateStart && input.dateEnd) { if (input.dateStart && input.dateEnd) {
@ -173,9 +173,9 @@ export const offersRouter = createRouter().query('list', {
} }
if (input.salaryMin && input.salaryMax) { if (input.salaryMin && input.salaryMax) {
const salary = offer.OffersFullTime?.totalCompensation.value const salary = offer.offersFullTime?.totalCompensation.value
? offer.OffersFullTime?.totalCompensation.value ? offer.offersFullTime?.totalCompensation.value
: offer.OffersIntern?.monthlySalary.value; : offer.offersIntern?.monthlySalary.value;
if (!salary) { if (!salary) {
throw new TRPCError({ throw new TRPCError({
@ -213,13 +213,13 @@ export const offersRouter = createRouter().query('list', {
} }
if (sortingKey === 'totalCompensation') { if (sortingKey === 'totalCompensation') {
const salary1 = offer1.OffersFullTime?.totalCompensation.value const salary1 = offer1.offersFullTime?.totalCompensation.value
? offer1.OffersFullTime?.totalCompensation.value ? offer1.offersFullTime?.totalCompensation.value
: offer1.OffersIntern?.monthlySalary.value; : offer1.offersIntern?.monthlySalary.value;
const salary2 = offer2.OffersFullTime?.totalCompensation.value const salary2 = offer2.offersFullTime?.totalCompensation.value
? offer2.OffersFullTime?.totalCompensation.value ? offer2.offersFullTime?.totalCompensation.value
: offer2.OffersIntern?.monthlySalary.value; : offer2.offersIntern?.monthlySalary.value;
if (!salary1 || !salary2) { if (!salary1 || !salary2) {
throw new TRPCError({ throw new TRPCError({
@ -259,13 +259,13 @@ export const offersRouter = createRouter().query('list', {
} }
if (sortingKey === 'totalCompensation') { if (sortingKey === 'totalCompensation') {
const salary1 = offer1.OffersFullTime?.totalCompensation.value const salary1 = offer1.offersFullTime?.totalCompensation.value
? offer1.OffersFullTime?.totalCompensation.value ? offer1.offersFullTime?.totalCompensation.value
: offer1.OffersIntern?.monthlySalary.value; : offer1.offersIntern?.monthlySalary.value;
const salary2 = offer2.OffersFullTime?.totalCompensation.value const salary2 = offer2.offersFullTime?.totalCompensation.value
? offer2.OffersFullTime?.totalCompensation.value ? offer2.offersFullTime?.totalCompensation.value
: offer2.OffersIntern?.monthlySalary.value; : offer2.offersIntern?.monthlySalary.value;
if (!salary1 || !salary2) { if (!salary1 || !salary2) {
throw new TRPCError({ throw new TRPCError({

Loading…
Cancel
Save