[offers][fix] fix create profile bugs

pull/353/head
Stuart Long Chay Boon 3 years ago
parent ee20ed683d
commit d5d74b7b4b

@ -309,13 +309,15 @@ model OffersOffer {
jobType JobType jobType JobType
OffersIntern OffersIntern? OffersIntern OffersIntern? @relation(fields: [offersInternId], references: [id])
OffersFullTime OffersFullTime? offersInternId String? @unique
OffersFullTime OffersFullTime? @relation(fields: [offersFullTimeId], references: [id])
offersFullTimeId String? @unique
} }
model OffersIntern { model OffersIntern {
offerId String @id id String @id @default(cuid())
offer OffersOffer @relation(fields: [offerId], references: [id])
title String title String
specialization String specialization String
@ -323,12 +325,12 @@ model OffersIntern {
startYear Int startYear Int
monthlySalary OffersCurrency @relation(fields: [monthlySalaryId], references: [id]) monthlySalary OffersCurrency @relation(fields: [monthlySalaryId], references: [id])
monthlySalaryId String @unique monthlySalaryId String @unique
OffersOffer OffersOffer?
} }
model OffersFullTime { model OffersFullTime {
offerId String @id id String @id @default(cuid())
offer OffersOffer @relation(fields: [offerId], references: [id])
title String title String
specialization String specialization String
level String level String
@ -340,6 +342,8 @@ model OffersFullTime {
bonusId String @unique bonusId String @unique
stocks OffersCurrency @relation("OfferStocks", fields: [stocksId], references: [id]) stocks OffersCurrency @relation("OfferStocks", fields: [stocksId], references: [id])
stocksId String @unique stocksId String @unique
OffersOffer OffersOffer?
} }
// End of Offers project models. // End of Offers project models.

@ -3,6 +3,7 @@ import superjson from 'superjson';
import { companiesRouter } from './companies-router'; import { companiesRouter } from './companies-router';
import { createRouter } from './context'; import { createRouter } from './context';
import { offersRouter } from './offers'; import { offersRouter } from './offers';
import { offersProfileRouter } from './offers-profile-router';
import { protectedExampleRouter } from './protected-example-router'; import { protectedExampleRouter } from './protected-example-router';
import { questionsAnswerCommentRouter } from './questions-answer-comment-router'; import { questionsAnswerCommentRouter } from './questions-answer-comment-router';
import { questionsAnswerRouter } from './questions-answer-router'; import { questionsAnswerRouter } from './questions-answer-router';
@ -34,7 +35,8 @@ export const appRouter = createRouter()
.merge('questions.answers.', questionsAnswerRouter) .merge('questions.answers.', questionsAnswerRouter)
.merge('questions.questions.comments.', questionsQuestionCommentRouter) .merge('questions.questions.comments.', questionsQuestionCommentRouter)
.merge('questions.questions.', questionsQuestionRouter) .merge('questions.questions.', questionsQuestionRouter)
.merge('offers.', offersRouter); .merge('offers.', offersRouter)
.merge('offers.profile.', offersProfileRouter);
// Export type definition of API // Export type definition of API
export type AppRouter = typeof appRouter; export type AppRouter = typeof appRouter;

@ -1,4 +1,4 @@
import crypto from "crypto"; import crypto, { randomUUID } from "crypto";
import { z } from "zod"; import { z } from "zod";
import { Prisma } from "@prisma/client"; import { Prisma } from "@prisma/client";
@ -61,7 +61,7 @@ export const offersProfileRouter = createProtectedRouter().mutation(
domain: z.string(), domain: z.string(),
yoe: z.number() yoe: z.number()
})), })),
totalYoe: z.number(), totalYoe: z.number().optional(),
}), }),
offers: z.array(offer) offers: z.array(offer)
}), }),
@ -90,9 +90,9 @@ export const offersProfileRouter = createProtectedRouter().mutation(
experiences: { experiences: {
create: create:
input.background.experiences.map((x) => { input.background.experiences.map((x) => {
if (x.jobType === "INTERN" && x.totalCompensation?.currency !== undefined && x.totalCompensation.value !== undefined) { if (x.jobType === "FULLTIME" && x.totalCompensation?.currency !== undefined && x.totalCompensation.value !== undefined) {
return { return {
companyId: { company: {
connect: { connect: {
id: x.companyId id: x.companyId
} }
@ -110,9 +110,9 @@ export const offersProfileRouter = createProtectedRouter().mutation(
}, },
} }
} }
if (x.jobType === "FULLTIME" && x.monthlySalary?.currency !== undefined && x.monthlySalary.value !== undefined) { if (x.jobType === "INTERN" && x.monthlySalary?.currency !== undefined && x.monthlySalary.value !== undefined) {
return { return {
companyId: { company: {
connect: { connect: {
id: x.companyId id: x.companyId
} }
@ -148,22 +148,67 @@ export const offersProfileRouter = createProtectedRouter().mutation(
offers: { offers: {
create: create:
input.offers.map((x) => { input.offers.map((x) => {
if (x.jobType === "INTERN" || x.jobType === "FULLTIME") { if (x.jobType === "INTERN" && x.job.internshipCycle !== undefined && x.job.monthlySalary?.currency !== undefined && x.job.monthlySalary.value !== undefined && x.job.startYear !== undefined) {
return { return {
// OffersIntern: { OffersIntern: {
// create: { create: {
// internshipCycle: x.job.internshipCycle, internshipCycle: x.job.internshipCycle,
// monthlySalary: { monthlySalary: {
// create: { create: {
// currency: x.job.monthlySalary?.currency, currency: x.job.monthlySalary?.currency,
// value: x.job.monthlySalary?.value value: x.job.monthlySalary?.value
// } }
// }, },
// specialization: x.job.specialization, specialization: x.job.specialization,
// startYear: x.job.startYear, startYear: x.job.startYear,
// title: x.job.title, title: x.job.title,
// } }
// }, },
comments: x.comments,
company: {
connect: {
id: x.companyId
}
},
jobType: x.jobType,
location: x.location,
monthYearReceived: x.monthYearReceived,
negotiationStrategy: x.negotiationStrategy
}
}
if (x.jobType === "FULLTIME" && x.job.base?.currency !== undefined && x.job.base?.value !== undefined && x.job.bonus?.currency !== undefined && x.job.bonus?.value !== undefined && x.job.stocks?.currency !== undefined && x.job.stocks?.value !== undefined && x.job.totalCompensation?.currency !== undefined && x.job.totalCompensation?.value !== undefined && x.job.level !== undefined) {
return {
OffersFullTime: {
create: {
baseSalary: {
create: {
currency: x.job.base?.currency,
value: x.job.base?.value
}
},
bonus: {
create: {
currency: x.job.bonus?.currency,
value: x.job.bonus?.value
}
},
level: x.job.level,
specialization: x.job.specialization,
stocks: {
create: {
currency: x.job.stocks?.currency,
value: x.job.stocks?.value,
}
},
title: x.job.title,
totalCompensation: {
create: {
currency: x.job.totalCompensation?.currency,
value: x.job.totalCompensation?.value,
}
},
}
},
comments: x.comments, comments: x.comments,
company: { company: {
connect: { connect: {
@ -176,123 +221,46 @@ export const offersProfileRouter = createProtectedRouter().mutation(
negotiationStrategy: x.negotiationStrategy negotiationStrategy: x.negotiationStrategy
} }
} }
// If (x.jobType === "FULLTIME") {
// return {
// // OffersFullTime: {
// // create: {
// // baseSalaryId: {
// // create: {
// // currency: x.job.base?.currency,
// // value: x.job.base?.value
// // }
// // },
// // bonusId: {
// // create: {
// // currency: x.job.bonus?.currency,
// // value: x.job.bonus?.value
// // }
// // },
// // level: x.job.level,
// // specialization: x.job.specialization,
// // startYear: x.job.startYear,
// // stocks: {
// // create: {
// // currency: x.job.stocks?.currency,
// // value: x.job.stocks?.value,
// // }
// // },
// // title: x.job.title,
// // }
// // },
// comments: x.comments,
// company: {
// connect: {
// id: x.companyId
// }
// },
// jobType: x.jobType,
// location: x.location,
// monthYearReceived: x.monthYearReceived,
// negotiationStrategy: x.negotiationStrategy
// }
// }
// Throw error // Throw error
throw Prisma.PrismaClientKnownRequestError throw Prisma.PrismaClientKnownRequestError
}) })
}, },
profileName: "anonymous account", profileName: randomUUID(),
}, },
// Include: { include: {
// select: { background: {
// id: true include: {
// } educations: true,
// } experiences: {
}); include: {
company: true,
// Create specific jobs monthlySalary: true,
input.offers.map((x) => { totalCompensation: true
if (x.jobType === "INTERN" && x.job.internshipCycle !== undefined && x.job.monthlySalary?.currency !== undefined && x.job.monthlySalary.value !== undefined && x.job.startYear !== undefined) {
ctx.prisma.offersIntern.create({
data: {
internshipCycle: x.job.internshipCycle,
monthlySalary: {
create: {
currency: x.job.monthlySalary?.currency,
value: x.job.monthlySalary?.value
}
},
offer: {
connect: {
id: profile.id
} }
}, },
specialization: x.job.specialization, specificYoes: true
startYear: x.job.startYear,
title: x.job.title,
} }
}) },
} else if (x.jobType === "FULLTIME" && x.job.startYear !== undefined && x.job.base?.currency !== undefined && x.job.base?.value !== undefined && x.job.bonus?.currency !== undefined && x.job.bonus?.value !== undefined && x.job.stocks?.currency !== undefined && x.job.stocks?.value !== undefined && x.job.totalCompensation?.currency !== undefined && x.job.totalCompensation?.value !== undefined && x.job.level !== undefined) { offers: {
ctx.prisma.offersFullTime.create({ include: {
data: { OffersFullTime: {
baseSalary: { include: {
create: { baseSalary: true,
currency: x.job.base?.currency, bonus: true,
value: x.job.base?.value stocks: true,
} totalCompensation: true
},
bonus: {
create: {
currency: x.job.bonus?.currency,
value: x.job.bonus?.value
}
},
level: x.job.level,
offer: {
connect: {
id: profile.id
}
},
specialization: x.job.specialization,
stocks: {
create: {
currency: x.job.stocks?.currency,
value: x.job.stocks?.value,
} }
}, },
title: x.job.title, OffersIntern: {
totalCompensation: { include: {
create: { monthlySalary: true
currency: x.job.totalCompensation?.currency,
value: x.job.totalCompensation?.value,
} }
}, }
} }
}) }
} },
});
throw Prisma.PrismaClientKnownRequestError
})
// TODO: add analysis to profile object then return // TODO: add analysis to profile object then return
return profile return profile

Loading…
Cancel
Save