diff --git a/apps/portal/prisma/schema.prisma b/apps/portal/prisma/schema.prisma index b4412d0f..70a88985 100644 --- a/apps/portal/prisma/schema.prisma +++ b/apps/portal/prisma/schema.prisma @@ -309,13 +309,15 @@ model OffersOffer { jobType JobType - OffersIntern OffersIntern? - OffersFullTime OffersFullTime? + OffersIntern OffersIntern? @relation(fields: [offersInternId], references: [id]) + offersInternId String? @unique + + OffersFullTime OffersFullTime? @relation(fields: [offersFullTimeId], references: [id]) + offersFullTimeId String? @unique } model OffersIntern { - offerId String @id - offer OffersOffer @relation(fields: [offerId], references: [id]) + id String @id @default(cuid()) title String specialization String @@ -323,12 +325,12 @@ model OffersIntern { startYear Int monthlySalary OffersCurrency @relation(fields: [monthlySalaryId], references: [id]) monthlySalaryId String @unique + + OffersOffer OffersOffer? } model OffersFullTime { - offerId String @id - offer OffersOffer @relation(fields: [offerId], references: [id]) - + id String @id @default(cuid()) title String specialization String level String @@ -340,6 +342,8 @@ model OffersFullTime { bonusId String @unique stocks OffersCurrency @relation("OfferStocks", fields: [stocksId], references: [id]) stocksId String @unique + + OffersOffer OffersOffer? } // End of Offers project models. diff --git a/apps/portal/src/server/router/index.ts b/apps/portal/src/server/router/index.ts index 3f899103..c018c3f7 100644 --- a/apps/portal/src/server/router/index.ts +++ b/apps/portal/src/server/router/index.ts @@ -3,6 +3,7 @@ import superjson from 'superjson'; import { companiesRouter } from './companies-router'; import { createRouter } from './context'; import { offersRouter } from './offers'; +import { offersProfileRouter } from './offers-profile-router'; import { protectedExampleRouter } from './protected-example-router'; import { questionsAnswerCommentRouter } from './questions-answer-comment-router'; import { questionsAnswerRouter } from './questions-answer-router'; @@ -34,7 +35,8 @@ export const appRouter = createRouter() .merge('questions.answers.', questionsAnswerRouter) .merge('questions.questions.comments.', questionsQuestionCommentRouter) .merge('questions.questions.', questionsQuestionRouter) - .merge('offers.', offersRouter); + .merge('offers.', offersRouter) + .merge('offers.profile.', offersProfileRouter); // Export type definition of API export type AppRouter = typeof appRouter; diff --git a/apps/portal/src/server/router/offers-profile-router.ts b/apps/portal/src/server/router/offers-profile-router.ts index afc245ee..286b6e5a 100644 --- a/apps/portal/src/server/router/offers-profile-router.ts +++ b/apps/portal/src/server/router/offers-profile-router.ts @@ -1,4 +1,4 @@ -import crypto from "crypto"; +import crypto, { randomUUID } from "crypto"; import { z } from "zod"; import { Prisma } from "@prisma/client"; @@ -61,7 +61,7 @@ export const offersProfileRouter = createProtectedRouter().mutation( domain: z.string(), yoe: z.number() })), - totalYoe: z.number(), + totalYoe: z.number().optional(), }), offers: z.array(offer) }), @@ -90,9 +90,9 @@ export const offersProfileRouter = createProtectedRouter().mutation( experiences: { create: 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 { - companyId: { + company: { connect: { 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 { - companyId: { + company: { connect: { id: x.companyId } @@ -148,22 +148,67 @@ export const offersProfileRouter = createProtectedRouter().mutation( offers: { create: 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 { - // OffersIntern: { - // create: { - // internshipCycle: x.job.internshipCycle, - // monthlySalary: { - // create: { - // currency: x.job.monthlySalary?.currency, - // value: x.job.monthlySalary?.value - // } - // }, - // specialization: x.job.specialization, - // startYear: x.job.startYear, - // title: x.job.title, - // } - // }, + OffersIntern: { + create: { + internshipCycle: x.job.internshipCycle, + monthlySalary: { + create: { + currency: x.job.monthlySalary?.currency, + value: x.job.monthlySalary?.value + } + }, + specialization: x.job.specialization, + startYear: x.job.startYear, + 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, company: { connect: { @@ -176,123 +221,46 @@ export const offersProfileRouter = createProtectedRouter().mutation( 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 Prisma.PrismaClientKnownRequestError }) }, - profileName: "anonymous account", + profileName: randomUUID(), }, - // Include: { - // select: { - // id: true - // } - // } - }); - - // Create specific jobs - input.offers.map((x) => { - 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 + include: { + background: { + include: { + educations: true, + experiences: { + include: { + company: true, + monthlySalary: true, + totalCompensation: true } }, - specialization: x.job.specialization, - startYear: x.job.startYear, - title: x.job.title, + specificYoes: true } - }) - } 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) { - ctx.prisma.offersFullTime.create({ - data: { - 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, - offer: { - connect: { - id: profile.id - } - }, - specialization: x.job.specialization, - stocks: { - create: { - currency: x.job.stocks?.currency, - value: x.job.stocks?.value, + }, + offers: { + include: { + OffersFullTime: { + include: { + baseSalary: true, + bonus: true, + stocks: true, + totalCompensation: true } }, - title: x.job.title, - totalCompensation: { - create: { - currency: x.job.totalCompensation?.currency, - value: x.job.totalCompensation?.value, + OffersIntern: { + include: { + monthlySalary: true } - }, + } } - }) - } - - throw Prisma.PrismaClientKnownRequestError - }) + } + }, + }); // TODO: add analysis to profile object then return return profile