[offers][chore] Create types for API responses

pull/390/head
BryannYeap 3 years ago
parent 9f24e0bcca
commit 3eb568dc51

@ -308,8 +308,8 @@ model OffersOffer {
monthYearReceived DateTime monthYearReceived DateTime
location String location String
negotiationStrategy String? negotiationStrategy String
comments String? comments String
jobType JobType jobType JobType

@ -43,25 +43,23 @@ export default function OfferProfile() {
if (data?.offers) { if (data?.offers) {
const filteredOffers: Array<OfferEntity> = data const filteredOffers: Array<OfferEntity> = data
? data?.offers.map((res) => { ? data?.offers.map((res) => {
if (res.OfferFullTime) { if (res.offersFullTime) {
const filteredOffer: OfferEntity = { const filteredOffer: OfferEntity = {
base: convertCurrencyToString( base: convertCurrencyToString(
res.OfferFullTime.baseSalary, res.offersFullTime.baseSalary,
),
bonus: convertCurrencyToString(
res.OfferFullTime.bonus,
), ),
bonus: convertCurrencyToString(res.offersFullTime.bonus),
companyName: res.company.name, companyName: res.company.name,
id: res.OfferFullTime.id, id: res.offersFullTime.id,
jobLevel: res.OfferFullTime.level, jobLevel: res.offersFullTime.level,
jobTitle: res.OfferFullTime.title, jobTitle: res.offersFullTime.title,
location: res.location, location: res.location,
negotiationStrategy: res.negotiationStrategy || '', negotiationStrategy: res.negotiationStrategy || '',
otherComment: res.comments || '', otherComment: res.comments || '',
receivedMonth: formatDate(res.monthYearReceived), receivedMonth: formatDate(res.monthYearReceived),
stocks: convertCurrencyToString(res.OfferFullTime.stocks), stocks: convertCurrencyToString(res.offersFullTime.stocks),
totalCompensation: convertCurrencyToString( totalCompensation: convertCurrencyToString(
res.OfferFullTime.totalCompensation, res.offersFullTime.totalCompensation,
), ),
}; };
@ -69,11 +67,11 @@ export default function OfferProfile() {
} }
const filteredOffer: OfferEntity = { const filteredOffer: OfferEntity = {
companyName: res.company.name, companyName: res.company.name,
id: res.OfferIntern!.id, id: res.offersIntern!.id,
jobTitle: res.OfferIntern!.title, jobTitle: res.offersIntern!.title,
location: res.location, location: res.location,
monthlySalary: convertCurrencyToString( monthlySalary: convertCurrencyToString(
res.OfferIntern!.monthlySalary, res.offersIntern!.monthlySalary,
), ),
negotiationStrategy: res.negotiationStrategy || '', negotiationStrategy: res.negotiationStrategy || '',
otherComment: res.comments || '', otherComment: res.comments || '',

@ -586,4 +586,4 @@ export const offersAnalysisRouter = createRouter()
analysis.topCompanyOffers, analysis.topCompanyOffers,
); );
}, },
}); });

@ -3,262 +3,266 @@ import * as trpc from '@trpc/server';
import { createProtectedRouter } from '../context'; import { createProtectedRouter } from '../context';
import type { Reply } from '~/types/offers-profile'; import type { Reply } from '~/types/offers';
export const offersCommentsRouter = createProtectedRouter() export const offersCommentsRouter = createProtectedRouter()
.query('getComments', { .query('getComments', {
input: z.object({ input: z.object({
profileId: z.string() profileId: z.string(),
}), }),
async resolve({ ctx, input }) { async resolve({ ctx, input }) {
const profile = await ctx.prisma.offersProfile.findFirst({
const profile = await ctx.prisma.offersProfile.findFirst({ where: {
where: { id: input.profileId,
id: input.profileId },
} });
})
const result = await ctx.prisma.offersProfile.findFirst({ const result = await ctx.prisma.offersProfile.findFirst({
include: {
discussion: {
include: {
replies: {
include: { include: {
discussion: { user: true,
include: {
replies: {
include: {
user: true
}
},
replyingTo: true,
user: true
}
}
}, },
where: { },
id: input.profileId replyingTo: true,
} user: true,
}) },
},
if (result) { },
return result.discussion where: {
.filter((x: Reply) => x.replyingToId === null) id: input.profileId,
.map((x: Reply) => { },
if (x.user == null) { });
x.user = {
email: "",
emailVerified: null,
id: "",
image: "",
name: profile?.profileName ?? "<missing name>"
}
}
x.replies?.map((y) => { if (result) {
if (y.user == null) { return result.discussion
y.user = { .filter((x: Reply) => x.replyingToId === null)
email: "", .map((x: Reply) => {
emailVerified: null, if (x.user == null) {
id: "", x.user = {
image: "", email: '',
name: profile?.profileName ?? "<missing name>" emailVerified: null,
} id: '',
} image: '',
}) name: profile?.profileName ?? '<missing name>',
return x; };
})
} }
return result x.replies?.map((y) => {
} if (y.user == null) {
}) y.user = {
.mutation("create", { email: '',
input: z.object({ emailVerified: null,
message: z.string(), id: '',
profileId: z.string(), image: '',
replyingToId: z.string().optional(), name: profile?.profileName ?? '<missing name>',
userId: z.string().optional() };
}), }
async resolve({ ctx, input }) { });
const createdReply = await ctx.prisma.offersReply.create({ return x;
data: { });
message: input.message, }
profile: {
connect: {
id: input.profileId
}
}
}
})
if (input.replyingToId) {
await ctx.prisma.offersReply.update({
data: {
replyingTo: {
connect: {
id: input.replyingToId
}
}
},
where: {
id: createdReply.id
}
})
}
if (input.userId) { return result;
await ctx.prisma.offersReply.update({ },
data: { })
user: { .mutation('create', {
connect: { input: z.object({
id: input.userId message: z.string(),
} profileId: z.string(),
} replyingToId: z.string().optional(),
}, userId: z.string().optional(),
where: { }),
id: createdReply.id async resolve({ ctx, input }) {
} const createdReply = await ctx.prisma.offersReply.create({
}) data: {
} message: input.message,
// Get replies profile: {
const result = await ctx.prisma.offersProfile.findFirst({ connect: {
include: { id: input.profileId,
discussion: { },
include: { },
replies: true, },
replyingTo: true, });
user: true
}
}
},
where: {
id: input.profileId
}
})
if (result) { if (input.replyingToId) {
return result.discussion.filter((x) => x.replyingToId === null) await ctx.prisma.offersReply.update({
} data: {
replyingTo: {
connect: {
id: input.replyingToId,
},
},
},
where: {
id: createdReply.id,
},
});
}
return result if (input.userId) {
} await ctx.prisma.offersReply.update({
}) data: {
.mutation("update", { user: {
input: z.object({ connect: {
id: z.string(), id: input.userId,
message: z.string(), },
profileId: z.string(), },
// Have to pass in either userID or token for validation },
token: z.string().optional(), where: {
userId: z.string().optional(), id: createdReply.id,
}), },
async resolve({ ctx, input }) { });
const messageToUpdate = await ctx.prisma.offersReply.findFirst({ }
where: { // Get replies
id: input.id const result = await ctx.prisma.offersProfile.findFirst({
} include: {
}) discussion: {
const profile = await ctx.prisma.offersProfile.findFirst({ include: {
where: { replies: true,
id: input.profileId, replyingTo: true,
}, user: true,
}); },
},
},
where: {
id: input.profileId,
},
});
const profileEditToken = profile?.editToken; if (result) {
return result.discussion.filter((x) => x.replyingToId === null);
}
// To validate user editing, OP or correct user return result;
// TODO: improve validation process },
if (profileEditToken === input.token || messageToUpdate?.userId === input.userId) { })
await ctx.prisma.offersReply.update({ .mutation('update', {
data: { input: z.object({
message: input.message id: z.string(),
}, message: z.string(),
where: { profileId: z.string(),
id: input.id // Have to pass in either userID or token for validation
} token: z.string().optional(),
}) userId: z.string().optional(),
}),
async resolve({ ctx, input }) {
const messageToUpdate = await ctx.prisma.offersReply.findFirst({
where: {
id: input.id,
},
});
const profile = await ctx.prisma.offersProfile.findFirst({
where: {
id: input.profileId,
},
});
const result = await ctx.prisma.offersProfile.findFirst({ const profileEditToken = profile?.editToken;
include: {
discussion: {
include: {
replies: true,
replyingTo: true,
user: true
}
}
},
where: {
id: input.profileId
}
})
if (result) { // To validate user editing, OP or correct user
return result.discussion.filter((x) => x.replyingToId === null) // TODO: improve validation process
} if (
profileEditToken === input.token ||
messageToUpdate?.userId === input.userId
) {
await ctx.prisma.offersReply.update({
data: {
message: input.message,
},
where: {
id: input.id,
},
});
return result const result = await ctx.prisma.offersProfile.findFirst({
} include: {
discussion: {
include: {
replies: true,
replyingTo: true,
user: true,
},
},
},
where: {
id: input.profileId,
},
});
throw new trpc.TRPCError({ if (result) {
code: 'UNAUTHORIZED', return result.discussion.filter((x) => x.replyingToId === null);
message: 'Wrong userId or token.'
})
} }
})
.mutation("delete", {
input: z.object({
id: z.string(),
profileId: z.string(),
// Have to pass in either userID or token for validation
token: z.string().optional(),
userId: z.string().optional(),
}),
async resolve({ ctx, input }) {
const messageToDelete = await ctx.prisma.offersReply.findFirst({
where: {
id: input.id
}
})
const profile = await ctx.prisma.offersProfile.findFirst({
where: {
id: input.profileId,
},
});
const profileEditToken = profile?.editToken; return result;
}
// To validate user editing, OP or correct user throw new trpc.TRPCError({
// TODO: improve validation process code: 'UNAUTHORIZED',
if (profileEditToken === input.token || messageToDelete?.userId === input.userId) { message: 'Wrong userId or token.',
await ctx.prisma.offersReply.delete({ });
where: { },
id: input.id })
} .mutation('delete', {
}) input: z.object({
const result = await ctx.prisma.offersProfile.findFirst({ id: z.string(),
include: { profileId: z.string(),
discussion: { // Have to pass in either userID or token for validation
include: { token: z.string().optional(),
replies: true, userId: z.string().optional(),
replyingTo: true, }),
user: true async resolve({ ctx, input }) {
} const messageToDelete = await ctx.prisma.offersReply.findFirst({
} where: {
}, id: input.id,
where: { },
id: input.profileId });
} const profile = await ctx.prisma.offersProfile.findFirst({
}) where: {
id: input.profileId,
},
});
if (result) { const profileEditToken = profile?.editToken;
return result.discussion.filter((x) => x.replyingToId === null)
}
return result // To validate user editing, OP or correct user
} // TODO: improve validation process
if (
profileEditToken === input.token ||
messageToDelete?.userId === input.userId
) {
await ctx.prisma.offersReply.delete({
where: {
id: input.id,
},
});
const result = await ctx.prisma.offersProfile.findFirst({
include: {
discussion: {
include: {
replies: true,
replyingTo: true,
user: true,
},
},
},
where: {
id: input.profileId,
},
});
throw new trpc.TRPCError({ if (result) {
code: 'UNAUTHORIZED', return result.discussion.filter((x) => x.replyingToId === null);
message: 'Wrong userId or token.'
})
} }
})
return result;
}
throw new trpc.TRPCError({
code: 'UNAUTHORIZED',
message: 'Wrong userId or token.',
});
},
});

@ -4,7 +4,7 @@ import * as trpc from '@trpc/server';
import { createRouter } from '../context'; import { createRouter } from '../context';
import type { OffersProfile } from '~/types/offers-profile'; import type { OffersProfile } from '~/types/offers';
const valuation = z.object({ const valuation = z.object({
currency: z.string(), currency: z.string(),
@ -19,33 +19,37 @@ const company = z.object({
logoUrl: z.string().nullish(), logoUrl: z.string().nullish(),
name: z.string(), name: z.string(),
slug: z.string(), slug: z.string(),
updatedAt: z.date() updatedAt: z.date(),
}) });
const offer = z.object({ const offer = z.object({
OffersFullTime: z.object({ OffersFullTime: z
baseSalary: valuation.nullish(), .object({
baseSalaryId: z.string().nullish(), baseSalary: valuation.nullish(),
bonus: valuation.nullish(), baseSalaryId: z.string().nullish(),
bonusId: z.string().nullish(), bonus: valuation.nullish(),
id: z.string().optional(), bonusId: z.string().nullish(),
level: z.string().nullish(), id: z.string().optional(),
specialization: z.string(), level: z.string().nullish(),
stocks: valuation.nullish(), specialization: z.string(),
stocksId: z.string().nullish(), stocks: valuation.nullish(),
title: z.string(), stocksId: z.string().nullish(),
totalCompensation: valuation.nullish(), title: z.string(),
totalCompensationId: z.string().nullish(), totalCompensation: valuation.nullish(),
}).nullish(), totalCompensationId: z.string().nullish(),
OffersIntern: z.object({ })
id: z.string().optional(), .nullish(),
internshipCycle: z.string().nullish(), OffersIntern: z
monthlySalary: valuation.nullish(), .object({
specialization: z.string(), id: z.string().optional(),
startYear: z.number().nullish(), internshipCycle: z.string().nullish(),
title: z.string(), monthlySalary: valuation.nullish(),
totalCompensation: valuation.nullish(), // Full time specialization: z.string(),
}).nullish(), startYear: z.number().nullish(),
title: z.string(),
totalCompensation: valuation.nullish(), // Full time
})
.nullish(),
comments: z.string().nullish(), comments: z.string().nullish(),
company: company.nullish(), company: company.nullish(),
companyId: z.string(), companyId: z.string(),
@ -72,7 +76,7 @@ const experience = z.object({
specialization: z.string().nullish(), specialization: z.string().nullish(),
title: z.string().nullish(), title: z.string().nullish(),
totalCompensation: valuation.nullish(), totalCompensation: valuation.nullish(),
totalCompensationId: z.string().nullish() totalCompensationId: z.string().nullish(),
}); });
const education = z.object({ const education = z.object({
@ -91,8 +95,8 @@ const reply = z.object({
messages: z.string().nullish(), messages: z.string().nullish(),
profileId: z.string().nullish(), profileId: z.string().nullish(),
replyingToId: z.string().nullish(), replyingToId: z.string().nullish(),
userId: z.string().nullish() userId: z.string().nullish(),
}) });
type WithIsEditable<T> = T & { type WithIsEditable<T> = T & {
isEditable: boolean; isEditable: boolean;
@ -144,7 +148,7 @@ export const offersProfileRouter = createRouter()
include: { include: {
replies: true, replies: true,
replyingTo: true, replyingTo: true,
user: true user: true,
}, },
}, },
offers: { offers: {
@ -172,7 +176,7 @@ export const offersProfileRouter = createRouter()
}); });
if (result) { if (result) {
return exclude(computeIsEditable(result, input.token), 'editToken') return exclude(computeIsEditable(result, input.token), 'editToken');
} }
throw new trpc.TRPCError({ throw new trpc.TRPCError({
@ -389,7 +393,8 @@ export const offersProfileRouter = createRouter()
title: x.OffersFullTime.title, title: x.OffersFullTime.title,
totalCompensation: { totalCompensation: {
create: { create: {
currency: x.OffersFullTime.totalCompensation?.currency, currency:
x.OffersFullTime.totalCompensation?.currency,
value: x.OffersFullTime.totalCompensation?.value, value: x.OffersFullTime.totalCompensation?.value,
}, },
}, },
@ -493,7 +498,7 @@ export const offersProfileRouter = createRouter()
backgroundId: z.string().optional(), backgroundId: z.string().optional(),
domain: z.string(), domain: z.string(),
id: z.string().optional(), id: z.string().optional(),
yoe: z.number() yoe: z.number(),
}), }),
), ),
totalYoe: z.number(), totalYoe: z.number(),
@ -505,7 +510,7 @@ export const offersProfileRouter = createRouter()
offers: z.array(offer), offers: z.array(offer),
profileName: z.string(), profileName: z.string(),
token: z.string(), token: z.string(),
userId: z.string().nullish() userId: z.string().nullish(),
}), }),
async resolve({ ctx, input }) { async resolve({ ctx, input }) {
const profileToUpdate = await ctx.prisma.offersProfile.findFirst({ const profileToUpdate = await ctx.prisma.offersProfile.findFirst({
@ -522,17 +527,17 @@ export const offersProfileRouter = createRouter()
}, },
where: { where: {
id: input.id, id: input.id,
} },
}); });
await ctx.prisma.offersBackground.update({ await ctx.prisma.offersBackground.update({
data: { data: {
totalYoe: input.background.totalYoe totalYoe: input.background.totalYoe,
}, },
where: { where: {
id: input.background.id id: input.background.id,
} },
}) });
for (const edu of input.background.educations) { for (const edu of input.background.educations) {
if (edu.id) { if (edu.id) {
@ -545,27 +550,26 @@ export const offersProfileRouter = createRouter()
type: edu.type, type: edu.type,
}, },
where: { where: {
id: edu.id id: edu.id,
} },
}) });
} else { } else {
await ctx.prisma.offersBackground.update({ await ctx.prisma.offersBackground.update({
data: { data: {
educations: { educations: {
create: create: {
{
endDate: edu.endDate, endDate: edu.endDate,
field: edu.field, field: edu.field,
school: edu.school, school: edu.school,
startDate: edu.startDate, startDate: edu.startDate,
type: edu.type, type: edu.type,
} },
} },
}, },
where: { where: {
id: input.background.id id: input.background.id,
} },
}) });
} }
} }
@ -579,9 +583,9 @@ export const offersProfileRouter = createRouter()
specialization: exp.specialization, specialization: exp.specialization,
}, },
where: { where: {
id: exp.id id: exp.id,
} },
}) });
if (exp.monthlySalary) { if (exp.monthlySalary) {
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersCurrency.update({
@ -590,9 +594,9 @@ export const offersProfileRouter = createRouter()
value: exp.monthlySalary.value, value: exp.monthlySalary.value,
}, },
where: { where: {
id: exp.monthlySalary.id id: exp.monthlySalary.id,
} },
}) });
} }
if (exp.totalCompensation) { if (exp.totalCompensation) {
@ -602,12 +606,16 @@ export const offersProfileRouter = createRouter()
value: exp.totalCompensation.value, value: exp.totalCompensation.value,
}, },
where: { where: {
id: exp.totalCompensation.id id: exp.totalCompensation.id,
} },
}) });
} }
} else if (!exp.id) { } else if (!exp.id) {
if (exp.jobType === 'FULLTIME' && exp.totalCompensation?.currency !== undefined && exp.totalCompensation.value !== undefined) { if (
exp.jobType === 'FULLTIME' &&
exp.totalCompensation?.currency !== undefined &&
exp.totalCompensation.value !== undefined
) {
if (exp.companyId) { if (exp.companyId) {
await ctx.prisma.offersBackground.update({ await ctx.prisma.offersBackground.update({
data: { data: {
@ -630,12 +638,12 @@ export const offersProfileRouter = createRouter()
}, },
}, },
}, },
} },
}, },
where: { where: {
id: input.background.id id: input.background.id,
} },
}) });
} else { } else {
await ctx.prisma.offersBackground.update({ await ctx.prisma.offersBackground.update({
data: { data: {
@ -652,16 +660,15 @@ export const offersProfileRouter = createRouter()
value: exp.totalCompensation?.value, value: exp.totalCompensation?.value,
}, },
}, },
} },
} },
}, },
where: { where: {
id: input.background.id id: input.background.id,
} },
}) });
} }
} } else if (
else if (
exp.jobType === 'INTERN' && exp.jobType === 'INTERN' &&
exp.monthlySalary?.currency !== undefined && exp.monthlySalary?.currency !== undefined &&
exp.monthlySalary.value !== undefined exp.monthlySalary.value !== undefined
@ -686,13 +693,13 @@ export const offersProfileRouter = createRouter()
}, },
specialization: exp.specialization, specialization: exp.specialization,
title: exp.title, title: exp.title,
} },
} },
}, },
where: { where: {
id: input.background.id id: input.background.id,
} },
}) });
} else { } else {
await ctx.prisma.offersBackground.update({ await ctx.prisma.offersBackground.update({
data: { data: {
@ -708,44 +715,42 @@ export const offersProfileRouter = createRouter()
}, },
specialization: exp.specialization, specialization: exp.specialization,
title: exp.title, title: exp.title,
} },
} },
}, },
where: { where: {
id: input.background.id id: input.background.id,
} },
}) });
} }
} }
} }
} }
for (const yoe of input.background.specificYoes) { for (const yoe of input.background.specificYoes) {
if (yoe.id) { if (yoe.id) {
await ctx.prisma.offersSpecificYoe.update({ await ctx.prisma.offersSpecificYoe.update({
data: { data: {
...yoe ...yoe,
}, },
where: { where: {
id: yoe.id id: yoe.id,
} },
}) });
} else { } else {
await ctx.prisma.offersBackground.update({ await ctx.prisma.offersBackground.update({
data: { data: {
specificYoes: { specificYoes: {
create: create: {
{
domain: yoe.domain, domain: yoe.domain,
yoe: yoe.yoe, yoe: yoe.yoe,
} },
} },
}, },
where: { where: {
id: input.background.id id: input.background.id,
} },
}) });
} }
} }
@ -760,42 +765,46 @@ export const offersProfileRouter = createRouter()
negotiationStrategy: offerToUpdate.negotiationStrategy, negotiationStrategy: offerToUpdate.negotiationStrategy,
}, },
where: { where: {
id: offerToUpdate.id id: offerToUpdate.id,
} },
}) });
if (offerToUpdate.jobType === "INTERN" || offerToUpdate.jobType === "FULLTIME") { if (
offerToUpdate.jobType === 'INTERN' ||
offerToUpdate.jobType === 'FULLTIME'
) {
await ctx.prisma.offersOffer.update({ await ctx.prisma.offersOffer.update({
data: { data: {
jobType: offerToUpdate.jobType jobType: offerToUpdate.jobType,
}, },
where: { where: {
id: offerToUpdate.id id: offerToUpdate.id,
} },
}) });
} }
if (offerToUpdate.OffersIntern?.monthlySalary) { if (offerToUpdate.OffersIntern?.monthlySalary) {
await ctx.prisma.offersIntern.update({ await ctx.prisma.offersIntern.update({
data: { data: {
internshipCycle: offerToUpdate.OffersIntern.internshipCycle ?? undefined, internshipCycle:
offerToUpdate.OffersIntern.internshipCycle ?? undefined,
specialization: offerToUpdate.OffersIntern.specialization, specialization: offerToUpdate.OffersIntern.specialization,
startYear: offerToUpdate.OffersIntern.startYear ?? undefined, startYear: offerToUpdate.OffersIntern.startYear ?? undefined,
title: offerToUpdate.OffersIntern.title, title: offerToUpdate.OffersIntern.title,
}, },
where: { where: {
id: offerToUpdate.OffersIntern.id, id: offerToUpdate.OffersIntern.id,
} },
}) });
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersCurrency.update({
data: { data: {
currency: offerToUpdate.OffersIntern.monthlySalary.currency, currency: offerToUpdate.OffersIntern.monthlySalary.currency,
value: offerToUpdate.OffersIntern.monthlySalary.value value: offerToUpdate.OffersIntern.monthlySalary.value,
}, },
where: { where: {
id: offerToUpdate.OffersIntern.monthlySalary.id id: offerToUpdate.OffersIntern.monthlySalary.id,
} },
}) });
} }
if (offerToUpdate.OffersFullTime?.totalCompensation) { if (offerToUpdate.OffersFullTime?.totalCompensation) {
@ -807,54 +816,55 @@ export const offersProfileRouter = createRouter()
}, },
where: { where: {
id: offerToUpdate.OffersFullTime.id, id: offerToUpdate.OffersFullTime.id,
} },
}) });
if (offerToUpdate.OffersFullTime.baseSalary) { if (offerToUpdate.OffersFullTime.baseSalary) {
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersCurrency.update({
data: { data: {
currency: offerToUpdate.OffersFullTime.baseSalary.currency, currency: offerToUpdate.OffersFullTime.baseSalary.currency,
value: offerToUpdate.OffersFullTime.baseSalary.value value: offerToUpdate.OffersFullTime.baseSalary.value,
}, },
where: { where: {
id: offerToUpdate.OffersFullTime.baseSalary.id id: offerToUpdate.OffersFullTime.baseSalary.id,
} },
}) });
} }
if (offerToUpdate.OffersFullTime.bonus) { if (offerToUpdate.OffersFullTime.bonus) {
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersCurrency.update({
data: { data: {
currency: offerToUpdate.OffersFullTime.bonus.currency, currency: offerToUpdate.OffersFullTime.bonus.currency,
value: offerToUpdate.OffersFullTime.bonus.value value: offerToUpdate.OffersFullTime.bonus.value,
}, },
where: { where: {
id: offerToUpdate.OffersFullTime.bonus.id id: offerToUpdate.OffersFullTime.bonus.id,
} },
}) });
} }
if (offerToUpdate.OffersFullTime.stocks) { if (offerToUpdate.OffersFullTime.stocks) {
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersCurrency.update({
data: { data: {
currency: offerToUpdate.OffersFullTime.stocks.currency, currency: offerToUpdate.OffersFullTime.stocks.currency,
value: offerToUpdate.OffersFullTime.stocks.value value: offerToUpdate.OffersFullTime.stocks.value,
}, },
where: { where: {
id: offerToUpdate.OffersFullTime.stocks.id id: offerToUpdate.OffersFullTime.stocks.id,
} },
}) });
} }
await ctx.prisma.offersCurrency.update({ await ctx.prisma.offersCurrency.update({
data: { data: {
currency: offerToUpdate.OffersFullTime.totalCompensation.currency, currency:
value: offerToUpdate.OffersFullTime.totalCompensation.value offerToUpdate.OffersFullTime.totalCompensation.currency,
value: offerToUpdate.OffersFullTime.totalCompensation.value,
}, },
where: { where: {
id: offerToUpdate.OffersFullTime.totalCompensation.id id: offerToUpdate.OffersFullTime.totalCompensation.id,
} },
}) });
} }
} else { } else {
if ( if (
offerToUpdate.jobType === "INTERN" && offerToUpdate.jobType === 'INTERN' &&
offerToUpdate.OffersIntern && offerToUpdate.OffersIntern &&
offerToUpdate.OffersIntern.internshipCycle && offerToUpdate.OffersIntern.internshipCycle &&
offerToUpdate.OffersIntern.monthlySalary?.currency && offerToUpdate.OffersIntern.monthlySalary?.currency &&
@ -867,14 +877,19 @@ export const offersProfileRouter = createRouter()
create: { create: {
OffersIntern: { OffersIntern: {
create: { create: {
internshipCycle: offerToUpdate.OffersIntern.internshipCycle, internshipCycle:
offerToUpdate.OffersIntern.internshipCycle,
monthlySalary: { monthlySalary: {
create: { create: {
currency: offerToUpdate.OffersIntern.monthlySalary?.currency, currency:
value: offerToUpdate.OffersIntern.monthlySalary?.value, offerToUpdate.OffersIntern.monthlySalary
?.currency,
value:
offerToUpdate.OffersIntern.monthlySalary?.value,
}, },
}, },
specialization: offerToUpdate.OffersIntern.specialization, specialization:
offerToUpdate.OffersIntern.specialization,
startYear: offerToUpdate.OffersIntern.startYear, startYear: offerToUpdate.OffersIntern.startYear,
title: offerToUpdate.OffersIntern.title, title: offerToUpdate.OffersIntern.title,
}, },
@ -889,13 +904,13 @@ export const offersProfileRouter = createRouter()
location: offerToUpdate.location, location: offerToUpdate.location,
monthYearReceived: offerToUpdate.monthYearReceived, monthYearReceived: offerToUpdate.monthYearReceived,
negotiationStrategy: offerToUpdate.negotiationStrategy, negotiationStrategy: offerToUpdate.negotiationStrategy,
} },
} },
}, },
where: { where: {
id: input.id, id: input.id,
} },
}) });
} }
if ( if (
offerToUpdate.jobType === 'FULLTIME' && offerToUpdate.jobType === 'FULLTIME' &&
@ -918,29 +933,39 @@ export const offersProfileRouter = createRouter()
create: { create: {
baseSalary: { baseSalary: {
create: { create: {
currency: offerToUpdate.OffersFullTime.baseSalary?.currency, currency:
value: offerToUpdate.OffersFullTime.baseSalary?.value, offerToUpdate.OffersFullTime.baseSalary
?.currency,
value:
offerToUpdate.OffersFullTime.baseSalary?.value,
}, },
}, },
bonus: { bonus: {
create: { create: {
currency: offerToUpdate.OffersFullTime.bonus?.currency, currency:
offerToUpdate.OffersFullTime.bonus?.currency,
value: offerToUpdate.OffersFullTime.bonus?.value, value: offerToUpdate.OffersFullTime.bonus?.value,
}, },
}, },
level: offerToUpdate.OffersFullTime.level, level: offerToUpdate.OffersFullTime.level,
specialization: offerToUpdate.OffersFullTime.specialization, specialization:
offerToUpdate.OffersFullTime.specialization,
stocks: { stocks: {
create: { create: {
currency: offerToUpdate.OffersFullTime.stocks?.currency, currency:
offerToUpdate.OffersFullTime.stocks?.currency,
value: offerToUpdate.OffersFullTime.stocks?.value, value: offerToUpdate.OffersFullTime.stocks?.value,
}, },
}, },
title: offerToUpdate.OffersFullTime.title, title: offerToUpdate.OffersFullTime.title,
totalCompensation: { totalCompensation: {
create: { create: {
currency: offerToUpdate.OffersFullTime.totalCompensation?.currency, currency:
value: offerToUpdate.OffersFullTime.totalCompensation?.value, offerToUpdate.OffersFullTime.totalCompensation
?.currency,
value:
offerToUpdate.OffersFullTime.totalCompensation
?.value,
}, },
}, },
}, },
@ -955,13 +980,13 @@ export const offersProfileRouter = createRouter()
location: offerToUpdate.location, location: offerToUpdate.location,
monthYearReceived: offerToUpdate.monthYearReceived, monthYearReceived: offerToUpdate.monthYearReceived,
negotiationStrategy: offerToUpdate.negotiationStrategy, negotiationStrategy: offerToUpdate.negotiationStrategy,
} },
} },
}, },
where: { where: {
id: input.id, id: input.id,
} },
}) });
} }
} }
} }
@ -985,7 +1010,7 @@ export const offersProfileRouter = createRouter()
include: { include: {
replies: true, replies: true,
replyingTo: true, replyingTo: true,
user: true user: true,
}, },
}, },
offers: { offers: {
@ -1013,7 +1038,7 @@ export const offersProfileRouter = createRouter()
}); });
if (result) { if (result) {
return exclude(computeIsEditable(result, input.token), 'editToken') return exclude(computeIsEditable(result, input.token), 'editToken');
} }
throw new trpc.TRPCError({ throw new trpc.TRPCError({
@ -1036,9 +1061,9 @@ export const offersProfileRouter = createRouter()
}), }),
async resolve({ ctx, input }) { async resolve({ ctx, input }) {
const profile = await ctx.prisma.offersProfile.findFirst({ const profile = await ctx.prisma.offersProfile.findFirst({
where: { where: {
id: input.profileId, id: input.profileId,
}, },
}); });
const profileEditToken = profile?.editToken; const profileEditToken = profile?.editToken;
@ -1048,25 +1073,25 @@ export const offersProfileRouter = createRouter()
data: { data: {
user: { user: {
connect: { connect: {
id: input.userId id: input.userId,
} },
} },
}, },
where: { where: {
id: input.profileId id: input.profileId,
} },
}) });
return { return {
id: updated.id, id: updated.id,
profileName: updated.profileName, profileName: updated.profileName,
userId: updated.userId userId: updated.userId,
} };
} }
throw new trpc.TRPCError({ throw new trpc.TRPCError({
code: 'UNAUTHORIZED', code: 'UNAUTHORIZED',
message: 'Invalid token.', message: 'Invalid token.',
}); });
} },
}); });

@ -1,130 +0,0 @@
export type OffersProfile = {
background?: Background | null;
createdAt: Date;
// Discussions: Array<discussion>;
editToken: string;
id: string;
offers: Array<Offer>;
profileName: string;
userId?: string | null;
};
export type Background = {
educations: Array<Education>;
experiences: Array<Experience>;
id: string;
offersProfileId: string;
specificYoes: Array<SpecificYoe>;
totalYoe?: number | null;
}
export type Experience = {
backgroundId: string;
company?: Company | null;
companyId?: string | null;
durationInMonths?: number | null;
id: string;
jobType?: string | null;
level?: string | null;
monthlySalary?: Valuation | null;
monthlySalaryId?: string | null;
specialization?: string | null;
title?: string | null;
totalCompensation?: Valuation | null;
totalCompensationId?: string | null;
}
export type Company = {
createdAt: Date;
description: string | null;
id: string;
logoUrl: string | null;
name: string;
slug: string;
updatedAt: Date
}
export type Valuation = {
currency: string;
id: string;
value: number;
}
export type Education = {
backgroundId: string;
endDate?: Date | null;
field?: string | null;
id: string;
school?: string | null;
startDate?: Date | null;
type?: string | null;
}
export type SpecificYoe = {
backgroundId: string;
domain: string;
id: string;
yoe: number;
}
export type Offer = {
OfferFullTime?: OfferFullTime | null;
OfferIntern?: OfferIntern | null;
comments?: string | null;
company: Company;
companyId: string;
id: string;
jobType: string;
location: string;
monthYearReceived: Date;
negotiationStrategy?: string | null;
offersFullTimeId?: string | null;
offersInternId?: string | null;
profileId: string;
}
export type OfferFullTime = {
baseSalary: Valuation;
baseSalaryId: string;
bonus: Valuation;
bonusId: string;
id: string;
level: string;
specialization: string;
stocks: Valuation;
stocksId: string;
title?: string;
totalCompensation: Valuation;
totalCompensationId: string;
}
export type OfferIntern = {
id: string;
internshipCycle: string;
monthlySalary: Valuation;
monthlySalaryId: string;
specialization: string;
startYear: number;
title?: string;
}
export type Reply = {
createdAt: Date;
id: string;
message: string;
// Profile: OffersProfile | null;
profileId: string;
replies: Array<Discussion>?;
replyingTo: Discussion?;
replyingToId: string | null;
user: User?;
userId: string | null;
}
export type User = {
email: string?;
emailVerified: Date?;
id: string;
image: string?;
name: string?;
}

@ -0,0 +1,181 @@
import type { JobType } from '@prisma/client';
export type OffersProfile = {
analysis: OffersAnalysis;
background: Background;
editToken: string?;
id: string;
isEditable: boolean;
offers: Array<ProfileOffer>;
profileName: string;
};
export type Background = {
educations: Array<Education>;
experiences: Array<Experience>;
id: string;
specificYoes: Array<SpecificYoe>;
totalYoe: number;
};
export type Experience = {
company: Company?;
durationInMonths: number?;
id: string;
jobType: JobType?;
level: string?;
monthlySalary: Valuation?;
specialization: string?;
title: string?;
totalCompensation: Valuation?;
};
export type Company = {
createdAt: Date;
description: string;
id: string;
logoUrl: string;
name: string;
slug: string;
updatedAt: Date;
};
export type Valuation = {
currency: string;
value: number;
};
export type Education = {
endDate: Date?;
field: string?;
id: string;
school: string?;
startDate: Date?;
type: string?;
};
export type SpecificYoe = {
backgroundId: string;
domain: string;
id: string;
yoe: number;
};
export type DashboardOffer = {
company: Company;
id: string;
income: Valuation;
monthYearReceived: Date;
title: string;
totalYoe: number;
};
export type ProfileOffer = {
comments: string;
company: Company;
id: string;
jobType: JobType;
location: string;
monthYearReceived: Date;
negotiationStrategy: string;
offersFullTime: OffersFullTime?;
offersIntern: OffersIntern?;
};
export type OffersFullTime = {
baseSalary: Valuation;
bonus: Valuation;
id: string;
level: string;
specialization: string;
stocks: Valuation;
title: string;
totalCompensation: Valuation;
};
export type OffersIntern = {
id: string;
internshipCycle: string;
monthlySalary: Valuation;
specialization: string;
startYear: number;
title: string;
};
export type Reply = {
createdAt: Date;
id: string;
message: string;
replies: Array<Reply>?;
replyingToId: string?;
user: User?;
};
export type User = {
email: string?;
emailVerified: Date?;
id: string;
image: string?;
name: string?;
};
export type GetOffersResponse = {
data: Array<DashboardOffer>;
paging: Paging;
};
export type Paging = {
currPage: number;
numOfItemsInPage: number;
numOfPages: number;
totalNumberOfOffers: number;
};
export type CreateOfferProfileResponse = {
analysis: OffersAnalysis;
id: string;
token: string;
};
export type OffersDiscussion = {
data: Array<OffersReply>;
};
export type OffersAnalysis = {
companyAnalysis: Array<Analysis>;
id: string;
overallAnalysis: Analysis;
overallHighestOffer: AnalysisHighestOffer;
profileId: string;
};
export type Analysis = {
noOfOffers: number;
percentile: number;
topPercentileOffers: Array<AnalysisOffer>;
};
export type AnalysisHighestOffer = {
company: Company;
id: string;
level: string;
location: string;
specialization: string;
totalYoe: number;
};
export type AnalysisOffer = {
company: Company;
id: string;
income: number;
jobType: JobType;
level: string;
location: string;
monthYearReceived: Date;
negotiationStrategy: string;
previousCompanies: Array<string>;
profileName: string;
specialization: string;
title: string;
totalYoe: number;
};
Loading…
Cancel
Save