[offers][fix] fix bugs create profile bugs

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

@ -1,5 +1,6 @@
import crypto from "crypto"; import crypto from "crypto";
import { z } from "zod"; import { z } from "zod";
import { Prisma } from "@prisma/client";
import { createProtectedRouter } from "./context"; import { createProtectedRouter } from "./context";
@ -31,22 +32,22 @@ const offer = z.object({
}) })
const experience = z.object({ const experience = z.object({
companyId: z.string(), companyId: z.string().optional(),
durationInMonths: z.number(), durationInMonths: z.number().optional(),
jobType: z.string(), jobType: z.string().optional(),
level: z.string().optional(), level: z.string().optional(),
monthlySalary: valuation.optional(), monthlySalary: valuation.optional(),
specialization: z.string(), specialization: z.string().optional(),
title: z.string(), title: z.string().optional(),
totalCompensation: valuation.optional(), totalCompensation: valuation.optional(),
}) })
const education = z.object({ const education = z.object({
endDate: z.date(), endDate: z.date().optional(),
field: z.string(), field: z.string().optional(),
school: z.string(), school: z.string().optional(),
startDate: z.date(), startDate: z.date().optional(),
type: z.string(), type: z.string().optional(),
}) })
export const offersProfileRouter = createProtectedRouter().mutation( export const offersProfileRouter = createProtectedRouter().mutation(
@ -72,12 +73,12 @@ export const offersProfileRouter = createProtectedRouter().mutation(
.update(Date.now().toString()) .update(Date.now().toString())
.digest("hex"); .digest("hex");
return await ctx.prisma.offersProfile.create({ const profile = await ctx.prisma.offersProfile.create({
data: { data: {
background: { background: {
create: { create: {
educations: { educations: {
create: [ create:
input.background.educations.map((x) => ({ input.background.educations.map((x) => ({
endDate: x.endDate, endDate: x.endDate,
field: x.field, field: x.field,
@ -85,12 +86,11 @@ export const offersProfileRouter = createProtectedRouter().mutation(
startDate: x.startDate, startDate: x.startDate,
type: x.type type: x.type
})) }))
]
}, },
experiences: { experiences: {
create: [ create:
input.background.experiences.map((x) => { input.background.experiences.map((x) => {
if (x.jobType === "Intern") { if (x.jobType === "INTERN" && x.totalCompensation?.currency !== undefined && x.totalCompensation.value !== undefined) {
return { return {
companyId: { companyId: {
connect: { connect: {
@ -110,7 +110,7 @@ export const offersProfileRouter = createProtectedRouter().mutation(
}, },
} }
} }
if (x.jobType === "FULLTIME" && x.monthlySalary?.currency !== undefined && x.monthlySalary.value !== undefined) {
return { return {
companyId: { companyId: {
connect: { connect: {
@ -122,16 +122,17 @@ export const offersProfileRouter = createProtectedRouter().mutation(
monthlySalary: { monthlySalary: {
create: { create: {
currency: x.monthlySalary?.currency, currency: x.monthlySalary?.currency,
value: x.totalCompensation?.value value: x.monthlySalary?.value
} }
}, },
specialization: x.specialization, specialization: x.specialization,
title: x.title, title: x.title,
} }
}
throw Prisma.PrismaClientKnownRequestError
}) })
]
}, },
specificYoes: { specificYoes: {
create: create:
@ -147,24 +148,24 @@ export const offersProfileRouter = createProtectedRouter().mutation(
offers: { offers: {
create: create:
input.offers.map((x) => { input.offers.map((x) => {
if (x.jobType === "Intern") { if (x.jobType === "INTERN" || x.jobType === "FULLTIME") {
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,
companyId: { company: {
connect: { connect: {
id: x.companyId id: x.companyId
} }
@ -175,24 +176,104 @@ export const offersProfileRouter = createProtectedRouter().mutation(
negotiationStrategy: x.negotiationStrategy negotiationStrategy: x.negotiationStrategy
} }
} }
return { // If (x.jobType === "FULLTIME") {
OffersFullTime: { // 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",
},
// 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: {
baseSalaryId: { 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: {
create: { create: {
currency: x.job.base?.currency, currency: x.job.base?.currency,
value: x.job.base?.value value: x.job.base?.value
} }
}, },
bonusId: { bonus: {
create: { create: {
currency: x.job.bonus?.currency, currency: x.job.bonus?.currency,
value: x.job.bonus?.value value: x.job.bonus?.value
} }
}, },
level: x.job.level, level: x.job.level,
offer: {
connect: {
id: profile.id
}
},
specialization: x.job.specialization, specialization: x.job.specialization,
startYear: x.job.startYear,
stocks: { stocks: {
create: { create: {
currency: x.job.stocks?.currency, currency: x.job.stocks?.currency,
@ -200,28 +281,21 @@ export const offersProfileRouter = createProtectedRouter().mutation(
} }
}, },
title: x.job.title, title: x.job.title,
totalCompensation: {
create: {
currency: x.job.totalCompensation?.currency,
value: x.job.totalCompensation?.value,
} }
}, },
comments: x.comments,
companyId: {
connect: {
id: x.companyId
}
},
jobType: x.jobType,
location: x.location,
monthYearReceived: x.monthYearReceived,
negotiationStrategy: x.negotiationStrategy
} }
}) })
},
profileName: "anonymous account",
} }
});
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