[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,28 +110,29 @@ export const offersProfileRouter = createProtectedRouter().mutation(
}, },
} }
} }
if (x.jobType === "FULLTIME" && x.monthlySalary?.currency !== undefined && x.monthlySalary.value !== undefined) {
return { return {
companyId: { companyId: {
connect: { connect: {
id: x.companyId id: x.companyId
} }
}, },
durationInMonths: x.durationInMonths, durationInMonths: x.durationInMonths,
jobType: x.jobType, jobType: x.jobType,
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,53 +176,126 @@ export const offersProfileRouter = createProtectedRouter().mutation(
negotiationStrategy: x.negotiationStrategy negotiationStrategy: x.negotiationStrategy
} }
} }
return { // If (x.jobType === "FULLTIME") {
OffersFullTime: { // return {
create: { // // OffersFullTime: {
baseSalaryId: { // // create: {
create: { // // baseSalaryId: {
currency: x.job.base?.currency, // // create: {
value: x.job.base?.value // // currency: x.job.base?.currency,
} // // value: x.job.base?.value
}, // // }
bonusId: { // // },
create: { // // bonusId: {
currency: x.job.bonus?.currency, // // create: {
value: x.job.bonus?.value // // currency: x.job.bonus?.currency,
} // // value: x.job.bonus?.value
}, // // }
level: x.job.level, // // },
specialization: x.job.specialization, // // level: x.job.level,
startYear: x.job.startYear, // // specialization: x.job.specialization,
stocks: { // // startYear: x.job.startYear,
create: { // // stocks: {
currency: x.job.stocks?.currency, // // create: {
value: x.job.stocks?.value, // // currency: x.job.stocks?.currency,
} // // value: x.job.stocks?.value,
}, // // }
title: x.job.title, // // },
} // // title: x.job.title,
}, // // }
comments: x.comments, // // },
companyId: { // comments: x.comments,
connect: { // company: {
id: x.companyId // connect: {
} // id: x.companyId
}, // }
jobType: x.jobType, // },
location: x.location, // jobType: x.jobType,
monthYearReceived: x.monthYearReceived, // location: x.location,
negotiationStrategy: x.negotiationStrategy // monthYearReceived: x.monthYearReceived,
} // negotiationStrategy: x.negotiationStrategy
// }
// }
// Throw error
throw Prisma.PrismaClientKnownRequestError
}) })
}, },
profileName: "anonymous account", 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: {
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: {
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,
}
},
title: x.job.title,
totalCompensation: {
create: {
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