parent
77ad895098
commit
d5edb6da60
@ -1,323 +1,353 @@
|
|||||||
import crypto, { randomUUID } 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';
|
||||||
|
|
||||||
import { createRouter } from "./context";
|
import { createRouter } from './context';
|
||||||
|
|
||||||
const valuation = z.object({
|
const valuation = z.object({
|
||||||
currency: z.string(),
|
currency: z.string(),
|
||||||
value: z.number(),
|
value: z.number(),
|
||||||
})
|
});
|
||||||
|
|
||||||
// TODO: handle both full time and intern
|
// TODO: handle both full time and intern
|
||||||
const offer = z.object({
|
const offer = z.object({
|
||||||
comments: z.string(),
|
comments: z.string(),
|
||||||
companyId: z.string(),
|
companyId: z.string(),
|
||||||
job: z.object({
|
job: z.object({
|
||||||
base: valuation.optional(), // Full time
|
base: valuation.optional(), // Full time
|
||||||
bonus: valuation.optional(), // Full time
|
bonus: valuation.optional(), // Full time
|
||||||
internshipCycle: z.string().optional(), // Intern
|
internshipCycle: z.string().optional(), // Intern
|
||||||
level: z.string().optional(), // Full time
|
level: z.string().optional(), // Full time
|
||||||
monthlySalary: valuation.optional(), // Intern
|
monthlySalary: valuation.optional(), // Intern
|
||||||
specialization: z.string(),
|
specialization: z.string(),
|
||||||
startYear: z.number().optional(), // Intern
|
startYear: z.number().optional(), // Intern
|
||||||
stocks: valuation.optional(), // Full time
|
stocks: valuation.optional(), // Full time
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
totalCompensation: valuation.optional(), // Full time
|
totalCompensation: valuation.optional(), // Full time
|
||||||
}),
|
}),
|
||||||
jobType: z.string(),
|
jobType: z.string(),
|
||||||
location: z.string(),
|
location: z.string(),
|
||||||
monthYearReceived: z.date(),
|
monthYearReceived: z.date(),
|
||||||
negotiationStrategy: z.string(),
|
negotiationStrategy: z.string(),
|
||||||
})
|
});
|
||||||
|
|
||||||
const experience = z.object({
|
const experience = z.object({
|
||||||
companyId: z.string().optional(),
|
companyId: z.string().optional(),
|
||||||
durationInMonths: z.number().optional(),
|
durationInMonths: z.number().optional(),
|
||||||
jobType: z.string().optional(),
|
jobType: z.string().optional(),
|
||||||
level: z.string().optional(),
|
level: z.string().optional(),
|
||||||
monthlySalary: valuation.optional(),
|
monthlySalary: valuation.optional(),
|
||||||
specialization: z.string().optional(),
|
specialization: z.string().optional(),
|
||||||
title: z.string().optional(),
|
title: z.string().optional(),
|
||||||
totalCompensation: valuation.optional(),
|
totalCompensation: valuation.optional(),
|
||||||
})
|
});
|
||||||
|
|
||||||
const education = z.object({
|
const education = z.object({
|
||||||
endDate: z.date().optional(),
|
endDate: z.date().optional(),
|
||||||
field: z.string().optional(),
|
field: z.string().optional(),
|
||||||
school: z.string().optional(),
|
school: z.string().optional(),
|
||||||
startDate: z.date().optional(),
|
startDate: z.date().optional(),
|
||||||
type: z.string().optional(),
|
type: z.string().optional(),
|
||||||
})
|
});
|
||||||
|
|
||||||
export const offersProfileRouter = createRouter()
|
export const offersProfileRouter = createRouter()
|
||||||
.query('listOne', {
|
.query('listOne', {
|
||||||
input: z.object({
|
input: z.object({
|
||||||
profileId: z.string(),
|
profileId: z.string(),
|
||||||
}),
|
}),
|
||||||
async resolve({ ctx, input }) {
|
async resolve({ ctx, input }) {
|
||||||
return await ctx.prisma.offersProfile.findFirst({
|
return await ctx.prisma.offersProfile.findFirst({
|
||||||
|
include: {
|
||||||
|
background: {
|
||||||
|
include: {
|
||||||
|
educations: true,
|
||||||
|
experiences: {
|
||||||
include: {
|
include: {
|
||||||
background: {
|
company: true,
|
||||||
include: {
|
monthlySalary: true,
|
||||||
educations: true,
|
totalCompensation: true,
|
||||||
experiences: {
|
|
||||||
include: {
|
|
||||||
company: true,
|
|
||||||
monthlySalary: true,
|
|
||||||
totalCompensation: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
specificYoes: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
discussion: {
|
|
||||||
include: {
|
|
||||||
replies: true,
|
|
||||||
replyingTo: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
offers: {
|
|
||||||
include: {
|
|
||||||
OffersFullTime: {
|
|
||||||
include: {
|
|
||||||
baseSalary: true,
|
|
||||||
bonus: true,
|
|
||||||
stocks: true,
|
|
||||||
totalCompensation: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
OffersIntern: {
|
|
||||||
include: {
|
|
||||||
monthlySalary: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
company: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
where: {
|
},
|
||||||
id: input.profileId
|
specificYoes: true,
|
||||||
}
|
},
|
||||||
})
|
},
|
||||||
}
|
discussion: {
|
||||||
})
|
include: {
|
||||||
.mutation(
|
replies: true,
|
||||||
'create',
|
replyingTo: true,
|
||||||
{
|
},
|
||||||
input: z.object({
|
},
|
||||||
background: z.object({
|
offers: {
|
||||||
educations: z.array(education),
|
include: {
|
||||||
experiences: z.array(experience),
|
OffersFullTime: {
|
||||||
specificYoes: z.array(z.object({
|
include: {
|
||||||
domain: z.string(),
|
baseSalary: true,
|
||||||
yoe: z.number(),
|
bonus: true,
|
||||||
})),
|
stocks: true,
|
||||||
totalYoe: z.number().optional(),
|
totalCompensation: true,
|
||||||
}),
|
},
|
||||||
offers: z.array(offer)
|
},
|
||||||
}),
|
OffersIntern: {
|
||||||
async resolve({ ctx, input }) {
|
include: {
|
||||||
|
monthlySalary: true,
|
||||||
// TODO: add more
|
},
|
||||||
const token = crypto
|
},
|
||||||
.createHash("sha256")
|
company: true,
|
||||||
.update(Date.now().toString())
|
},
|
||||||
.digest("hex");
|
},
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
id: input.profileId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.mutation('create', {
|
||||||
|
input: z.object({
|
||||||
|
background: z.object({
|
||||||
|
educations: z.array(education),
|
||||||
|
experiences: z.array(experience),
|
||||||
|
specificYoes: z.array(
|
||||||
|
z.object({
|
||||||
|
domain: z.string(),
|
||||||
|
yoe: z.number(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
totalYoe: z.number().optional(),
|
||||||
|
}),
|
||||||
|
offers: z.array(offer),
|
||||||
|
}),
|
||||||
|
async resolve({ ctx, input }) {
|
||||||
|
// TODO: add more
|
||||||
|
const token = crypto
|
||||||
|
.createHash('sha256')
|
||||||
|
.update(Date.now().toString())
|
||||||
|
.digest('hex');
|
||||||
|
|
||||||
const profile = await ctx.prisma.offersProfile.create({
|
const profile = await ctx.prisma.offersProfile.create({
|
||||||
data: {
|
data: {
|
||||||
background: {
|
background: {
|
||||||
|
create: {
|
||||||
|
educations: {
|
||||||
|
create: input.background.educations.map((x) => ({
|
||||||
|
endDate: x.endDate,
|
||||||
|
field: x.field,
|
||||||
|
school: x.school,
|
||||||
|
startDate: x.startDate,
|
||||||
|
type: x.type,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
experiences: {
|
||||||
|
create: input.background.experiences.map((x) => {
|
||||||
|
if (
|
||||||
|
x.jobType === 'FULLTIME' &&
|
||||||
|
x.totalCompensation?.currency !== undefined &&
|
||||||
|
x.totalCompensation.value !== undefined
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
company: {
|
||||||
|
connect: {
|
||||||
|
id: x.companyId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
durationInMonths: x.durationInMonths,
|
||||||
|
jobType: x.jobType,
|
||||||
|
level: x.level,
|
||||||
|
specialization: x.specialization,
|
||||||
|
title: x.title,
|
||||||
|
totalCompensation: {
|
||||||
create: {
|
create: {
|
||||||
educations: {
|
currency: x.totalCompensation?.currency,
|
||||||
create:
|
value: x.totalCompensation?.value,
|
||||||
input.background.educations.map((x) => ({
|
},
|
||||||
endDate: x.endDate,
|
},
|
||||||
field: x.field,
|
};
|
||||||
school: x.school,
|
}
|
||||||
startDate: x.startDate,
|
if (
|
||||||
type: x.type
|
x.jobType === 'INTERN' &&
|
||||||
}))
|
x.monthlySalary?.currency !== undefined &&
|
||||||
},
|
x.monthlySalary.value !== undefined
|
||||||
experiences: {
|
) {
|
||||||
create:
|
return {
|
||||||
input.background.experiences.map((x) => {
|
company: {
|
||||||
if (x.jobType === "FULLTIME" && x.totalCompensation?.currency !== undefined && x.totalCompensation.value !== undefined) {
|
connect: {
|
||||||
return {
|
id: x.companyId,
|
||||||
company: {
|
},
|
||||||
connect: {
|
},
|
||||||
id: x.companyId
|
durationInMonths: x.durationInMonths,
|
||||||
}
|
jobType: x.jobType,
|
||||||
},
|
monthlySalary: {
|
||||||
durationInMonths: x.durationInMonths,
|
create: {
|
||||||
jobType: x.jobType,
|
currency: x.monthlySalary?.currency,
|
||||||
level: x.level,
|
value: x.monthlySalary?.value,
|
||||||
specialization: x.specialization,
|
},
|
||||||
title: x.title,
|
},
|
||||||
totalCompensation: {
|
specialization: x.specialization,
|
||||||
create: {
|
title: x.title,
|
||||||
currency: x.totalCompensation?.currency,
|
};
|
||||||
value: x.totalCompensation?.value,
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (x.jobType === "INTERN" && x.monthlySalary?.currency !== undefined && x.monthlySalary.value !== undefined) {
|
|
||||||
return {
|
|
||||||
company: {
|
|
||||||
connect: {
|
|
||||||
id: x.companyId
|
|
||||||
}
|
|
||||||
},
|
|
||||||
durationInMonths: x.durationInMonths,
|
|
||||||
jobType: x.jobType,
|
|
||||||
monthlySalary: {
|
|
||||||
create: {
|
|
||||||
currency: x.monthlySalary?.currency,
|
|
||||||
value: x.monthlySalary?.value
|
|
||||||
}
|
|
||||||
},
|
|
||||||
specialization: x.specialization,
|
|
||||||
title: x.title,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw Prisma.PrismaClientKnownRequestError
|
|
||||||
|
|
||||||
})
|
throw Prisma.PrismaClientKnownRequestError;
|
||||||
},
|
}),
|
||||||
specificYoes: {
|
},
|
||||||
create:
|
specificYoes: {
|
||||||
input.background.specificYoes.map((x) => {
|
create: input.background.specificYoes.map((x) => {
|
||||||
return {
|
return {
|
||||||
domain: x.domain,
|
domain: x.domain,
|
||||||
yoe: x.yoe
|
yoe: x.yoe,
|
||||||
}
|
};
|
||||||
})
|
}),
|
||||||
},
|
},
|
||||||
totalYoe: input.background.totalYoe,
|
totalYoe: input.background.totalYoe,
|
||||||
}
|
},
|
||||||
|
},
|
||||||
|
editToken: token,
|
||||||
|
offers: {
|
||||||
|
create: 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
|
||||||
|
) {
|
||||||
|
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,
|
||||||
},
|
},
|
||||||
editToken: token,
|
},
|
||||||
offers: {
|
comments: x.comments,
|
||||||
create:
|
company: {
|
||||||
input.offers.map((x) => {
|
connect: {
|
||||||
if (x.jobType === "INTERN" && x.job.internshipCycle !== undefined && x.job.monthlySalary?.currency !== undefined && x.job.monthlySalary.value !== undefined && x.job.startYear !== undefined) {
|
id: x.companyId,
|
||||||
return {
|
},
|
||||||
OffersIntern: {
|
},
|
||||||
create: {
|
jobType: x.jobType,
|
||||||
internshipCycle: x.job.internshipCycle,
|
location: x.location,
|
||||||
monthlySalary: {
|
monthYearReceived: x.monthYearReceived,
|
||||||
create: {
|
negotiationStrategy: x.negotiationStrategy,
|
||||||
currency: x.job.monthlySalary?.currency,
|
};
|
||||||
value: x.job.monthlySalary?.value
|
}
|
||||||
}
|
if (
|
||||||
},
|
x.jobType === 'FULLTIME' &&
|
||||||
specialization: x.job.specialization,
|
x.job.base?.currency !== undefined &&
|
||||||
startYear: x.job.startYear,
|
x.job.base?.value !== undefined &&
|
||||||
title: x.job.title,
|
x.job.bonus?.currency !== undefined &&
|
||||||
}
|
x.job.bonus?.value !== undefined &&
|
||||||
},
|
x.job.stocks?.currency !== undefined &&
|
||||||
comments: x.comments,
|
x.job.stocks?.value !== undefined &&
|
||||||
company: {
|
x.job.totalCompensation?.currency !== undefined &&
|
||||||
connect: {
|
x.job.totalCompensation?.value !== undefined &&
|
||||||
id: x.companyId
|
x.job.level !== undefined
|
||||||
}
|
) {
|
||||||
},
|
return {
|
||||||
jobType: x.jobType,
|
OffersFullTime: {
|
||||||
location: x.location,
|
create: {
|
||||||
monthYearReceived: x.monthYearReceived,
|
baseSalary: {
|
||||||
negotiationStrategy: x.negotiationStrategy
|
create: {
|
||||||
}
|
currency: x.job.base?.currency,
|
||||||
}
|
value: x.job.base?.value,
|
||||||
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: {
|
bonus: {
|
||||||
create: {
|
create: {
|
||||||
baseSalary: {
|
currency: x.job.bonus?.currency,
|
||||||
create: {
|
value: x.job.bonus?.value,
|
||||||
currency: x.job.base?.currency,
|
},
|
||||||
value: x.job.base?.value
|
},
|
||||||
}
|
level: x.job.level,
|
||||||
},
|
specialization: x.job.specialization,
|
||||||
bonus: {
|
stocks: {
|
||||||
create: {
|
create: {
|
||||||
currency: x.job.bonus?.currency,
|
currency: x.job.stocks?.currency,
|
||||||
value: x.job.bonus?.value
|
value: x.job.stocks?.value,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
level: x.job.level,
|
title: x.job.title,
|
||||||
specialization: x.job.specialization,
|
totalCompensation: {
|
||||||
stocks: {
|
create: {
|
||||||
create: {
|
currency: x.job.totalCompensation?.currency,
|
||||||
currency: x.job.stocks?.currency,
|
value: x.job.totalCompensation?.value,
|
||||||
value: x.job.stocks?.value,
|
},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
title: x.job.title,
|
},
|
||||||
totalCompensation: {
|
comments: x.comments,
|
||||||
create: {
|
company: {
|
||||||
currency: x.job.totalCompensation?.currency,
|
connect: {
|
||||||
value: x.job.totalCompensation?.value,
|
id: x.companyId,
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
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: randomUUID().substring(0,10),
|
},
|
||||||
|
jobType: x.jobType,
|
||||||
|
location: x.location,
|
||||||
|
monthYearReceived: x.monthYearReceived,
|
||||||
|
negotiationStrategy: x.negotiationStrategy,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Throw error
|
||||||
|
throw Prisma.PrismaClientKnownRequestError;
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
profileName: randomUUID().substring(0, 10),
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
background: {
|
||||||
|
include: {
|
||||||
|
educations: true,
|
||||||
|
experiences: {
|
||||||
|
include: {
|
||||||
|
company: true,
|
||||||
|
monthlySalary: true,
|
||||||
|
totalCompensation: true,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
specificYoes: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
offers: {
|
||||||
|
include: {
|
||||||
|
OffersFullTime: {
|
||||||
include: {
|
include: {
|
||||||
background: {
|
baseSalary: true,
|
||||||
include: {
|
bonus: true,
|
||||||
educations: true,
|
stocks: true,
|
||||||
experiences: {
|
totalCompensation: true,
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
OffersIntern: {
|
||||||
|
include: {
|
||||||
|
monthlySalary: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: add analysis to profile object then return
|
// TODO: add analysis to profile object then return
|
||||||
return profile
|
return profile;
|
||||||
}
|
},
|
||||||
|
})
|
||||||
|
.mutation('delete', {
|
||||||
|
input: z.object({
|
||||||
|
id: z.string(),
|
||||||
|
}),
|
||||||
|
async resolve({ ctx, input }) {
|
||||||
|
return await ctx.prisma.offersProfile.delete({
|
||||||
|
where: {
|
||||||
|
id: input.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
},
|
},
|
||||||
);
|
});
|
||||||
|
Loading…
Reference in new issue