[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,22 @@ 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, comments: x.comments,
company: { company: {
connect: { connect: {
@ -176,85 +176,10 @@ export const offersProfileRouter = createProtectedRouter().mutation(
negotiationStrategy: x.negotiationStrategy negotiationStrategy: x.negotiationStrategy
} }
} }
// If (x.jobType === "FULLTIME") { 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 { return {
// // OffersFullTime: { 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",
},
// 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: { create: {
currency: x.job.monthlySalary?.currency,
value: x.job.monthlySalary?.value
}
},
offer: {
connect: {
id: profile.id
}
},
specialization: x.job.specialization,
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) {
ctx.prisma.offersFullTime.create({
data: {
baseSalary: { baseSalary: {
create: { create: {
currency: x.job.base?.currency, currency: x.job.base?.currency,
@ -268,11 +193,6 @@ export const offersProfileRouter = createProtectedRouter().mutation(
} }
}, },
level: x.job.level, level: x.job.level,
offer: {
connect: {
id: profile.id
}
},
specialization: x.job.specialization, specialization: x.job.specialization,
stocks: { stocks: {
create: { create: {
@ -288,11 +208,59 @@ export const offersProfileRouter = createProtectedRouter().mutation(
} }
}, },
} }
}) },
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 throw Prisma.PrismaClientKnownRequestError
}) })
},
profileName: randomUUID(),
},
include: {
background: {
include: {
educations: true,
experiences: {
include: {
company: true,
monthlySalary: true,
totalCompensation: true
}
},
specificYoes: true
}
},
offers: {
include: {
OffersFullTime: {
include: {
baseSalary: true,
bonus: true,
stocks: true,
totalCompensation: true
}
},
OffersIntern: {
include: {
monthlySalary: true
}
}
}
}
},
});
// TODO: add analysis to profile object then return // TODO: add analysis to profile object then return
return profile return profile

Loading…
Cancel
Save