From 3eb568dc51a98c1ccb5e969dc187e06aa5cfb9c8 Mon Sep 17 00:00:00 2001 From: BryannYeap Date: Tue, 18 Oct 2022 01:39:55 +0800 Subject: [PATCH] [offers][chore] Create types for API responses --- apps/portal/prisma/schema.prisma | 4 +- .../pages/offers/profile/[offerProfileId].tsx | 24 +- .../router/offers/offers-analysis-router.ts | 2 +- .../router/offers/offers-comments-router.ts | 474 +++++++++--------- .../router/offers/offers-profile-router.ts | 345 +++++++------ apps/portal/src/types/offers-profile.d.ts | 130 ----- apps/portal/src/types/offers.d.ts | 181 +++++++ 7 files changed, 619 insertions(+), 541 deletions(-) delete mode 100644 apps/portal/src/types/offers-profile.d.ts create mode 100644 apps/portal/src/types/offers.d.ts diff --git a/apps/portal/prisma/schema.prisma b/apps/portal/prisma/schema.prisma index aa29f612..07f5d51f 100644 --- a/apps/portal/prisma/schema.prisma +++ b/apps/portal/prisma/schema.prisma @@ -308,8 +308,8 @@ model OffersOffer { monthYearReceived DateTime location String - negotiationStrategy String? - comments String? + negotiationStrategy String + comments String jobType JobType diff --git a/apps/portal/src/pages/offers/profile/[offerProfileId].tsx b/apps/portal/src/pages/offers/profile/[offerProfileId].tsx index ba629b87..db1965ca 100644 --- a/apps/portal/src/pages/offers/profile/[offerProfileId].tsx +++ b/apps/portal/src/pages/offers/profile/[offerProfileId].tsx @@ -43,25 +43,23 @@ export default function OfferProfile() { if (data?.offers) { const filteredOffers: Array = data ? data?.offers.map((res) => { - if (res.OfferFullTime) { + if (res.offersFullTime) { const filteredOffer: OfferEntity = { base: convertCurrencyToString( - res.OfferFullTime.baseSalary, - ), - bonus: convertCurrencyToString( - res.OfferFullTime.bonus, + res.offersFullTime.baseSalary, ), + bonus: convertCurrencyToString(res.offersFullTime.bonus), companyName: res.company.name, - id: res.OfferFullTime.id, - jobLevel: res.OfferFullTime.level, - jobTitle: res.OfferFullTime.title, + id: res.offersFullTime.id, + jobLevel: res.offersFullTime.level, + jobTitle: res.offersFullTime.title, location: res.location, negotiationStrategy: res.negotiationStrategy || '', otherComment: res.comments || '', receivedMonth: formatDate(res.monthYearReceived), - stocks: convertCurrencyToString(res.OfferFullTime.stocks), + stocks: convertCurrencyToString(res.offersFullTime.stocks), totalCompensation: convertCurrencyToString( - res.OfferFullTime.totalCompensation, + res.offersFullTime.totalCompensation, ), }; @@ -69,11 +67,11 @@ export default function OfferProfile() { } const filteredOffer: OfferEntity = { companyName: res.company.name, - id: res.OfferIntern!.id, - jobTitle: res.OfferIntern!.title, + id: res.offersIntern!.id, + jobTitle: res.offersIntern!.title, location: res.location, monthlySalary: convertCurrencyToString( - res.OfferIntern!.monthlySalary, + res.offersIntern!.monthlySalary, ), negotiationStrategy: res.negotiationStrategy || '', otherComment: res.comments || '', diff --git a/apps/portal/src/server/router/offers/offers-analysis-router.ts b/apps/portal/src/server/router/offers/offers-analysis-router.ts index efa684af..3a836706 100644 --- a/apps/portal/src/server/router/offers/offers-analysis-router.ts +++ b/apps/portal/src/server/router/offers/offers-analysis-router.ts @@ -586,4 +586,4 @@ export const offersAnalysisRouter = createRouter() analysis.topCompanyOffers, ); }, - }); + }); \ No newline at end of file diff --git a/apps/portal/src/server/router/offers/offers-comments-router.ts b/apps/portal/src/server/router/offers/offers-comments-router.ts index 6e4cf6cc..11fcda8e 100644 --- a/apps/portal/src/server/router/offers/offers-comments-router.ts +++ b/apps/portal/src/server/router/offers/offers-comments-router.ts @@ -3,262 +3,266 @@ import * as trpc from '@trpc/server'; import { createProtectedRouter } from '../context'; -import type { Reply } from '~/types/offers-profile'; - +import type { Reply } from '~/types/offers'; export const offersCommentsRouter = createProtectedRouter() - .query('getComments', { - input: z.object({ - profileId: z.string() - }), - async resolve({ ctx, input }) { - - const profile = await ctx.prisma.offersProfile.findFirst({ - where: { - id: input.profileId - } - }) + .query('getComments', { + input: z.object({ + profileId: z.string(), + }), + async resolve({ ctx, input }) { + const profile = await ctx.prisma.offersProfile.findFirst({ + where: { + id: input.profileId, + }, + }); - const result = await ctx.prisma.offersProfile.findFirst({ + const result = await ctx.prisma.offersProfile.findFirst({ + include: { + discussion: { + include: { + replies: { include: { - discussion: { - include: { - replies: { - include: { - user: true - } - }, - replyingTo: true, - user: true - } - } + user: true, }, - where: { - id: input.profileId - } - }) - - if (result) { - return result.discussion - .filter((x: Reply) => x.replyingToId === null) - .map((x: Reply) => { - if (x.user == null) { - x.user = { - email: "", - emailVerified: null, - id: "", - image: "", - name: profile?.profileName ?? "" - } - } + }, + replyingTo: true, + user: true, + }, + }, + }, + where: { + id: input.profileId, + }, + }); - x.replies?.map((y) => { - if (y.user == null) { - y.user = { - email: "", - emailVerified: null, - id: "", - image: "", - name: profile?.profileName ?? "" - } - } - }) - return x; - }) + if (result) { + return result.discussion + .filter((x: Reply) => x.replyingToId === null) + .map((x: Reply) => { + if (x.user == null) { + x.user = { + email: '', + emailVerified: null, + id: '', + image: '', + name: profile?.profileName ?? '', + }; } - return result - } - }) - .mutation("create", { - input: z.object({ - message: z.string(), - profileId: z.string(), - replyingToId: z.string().optional(), - userId: z.string().optional() - }), - async resolve({ ctx, input }) { - const createdReply = await ctx.prisma.offersReply.create({ - 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 - } - }) - } + x.replies?.map((y) => { + if (y.user == null) { + y.user = { + email: '', + emailVerified: null, + id: '', + image: '', + name: profile?.profileName ?? '', + }; + } + }); + return x; + }); + } - if (input.userId) { - await ctx.prisma.offersReply.update({ - data: { - user: { - connect: { - id: input.userId - } - } - }, - where: { - id: createdReply.id - } - }) - } - // Get replies - const result = await ctx.prisma.offersProfile.findFirst({ - include: { - discussion: { - include: { - replies: true, - replyingTo: true, - user: true - } - } - }, - where: { - id: input.profileId - } - }) + return result; + }, + }) + .mutation('create', { + input: z.object({ + message: z.string(), + profileId: z.string(), + replyingToId: z.string().optional(), + userId: z.string().optional(), + }), + async resolve({ ctx, input }) { + const createdReply = await ctx.prisma.offersReply.create({ + data: { + message: input.message, + profile: { + connect: { + id: input.profileId, + }, + }, + }, + }); - if (result) { - return result.discussion.filter((x) => x.replyingToId === null) - } + if (input.replyingToId) { + await ctx.prisma.offersReply.update({ + data: { + replyingTo: { + connect: { + id: input.replyingToId, + }, + }, + }, + where: { + id: createdReply.id, + }, + }); + } - return result - } - }) - .mutation("update", { - input: z.object({ - id: z.string(), - message: 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 messageToUpdate = await ctx.prisma.offersReply.findFirst({ - where: { - id: input.id - } - }) - const profile = await ctx.prisma.offersProfile.findFirst({ - where: { - id: input.profileId, - }, - }); + if (input.userId) { + await ctx.prisma.offersReply.update({ + data: { + user: { + connect: { + id: input.userId, + }, + }, + }, + where: { + id: createdReply.id, + }, + }); + } + // Get replies + const result = await ctx.prisma.offersProfile.findFirst({ + include: { + discussion: { + include: { + replies: true, + 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 - // 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; + }, + }) + .mutation('update', { + input: z.object({ + id: z.string(), + message: 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 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({ - include: { - discussion: { - include: { - replies: true, - 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 + // 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({ - code: 'UNAUTHORIZED', - message: 'Wrong userId or token.' - }) + if (result) { + return result.discussion.filter((x) => x.replyingToId === null); } - }) - .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 - // 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({ + code: 'UNAUTHORIZED', + 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, + }, + }); - if (result) { - return result.discussion.filter((x) => x.replyingToId === null) - } + const profileEditToken = profile?.editToken; - 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({ - code: 'UNAUTHORIZED', - message: 'Wrong userId or token.' - }) + if (result) { + return result.discussion.filter((x) => x.replyingToId === null); } - }) \ No newline at end of file + + return result; + } + + throw new trpc.TRPCError({ + code: 'UNAUTHORIZED', + message: 'Wrong userId or token.', + }); + }, + }); diff --git a/apps/portal/src/server/router/offers/offers-profile-router.ts b/apps/portal/src/server/router/offers/offers-profile-router.ts index 09e073da..b25870aa 100644 --- a/apps/portal/src/server/router/offers/offers-profile-router.ts +++ b/apps/portal/src/server/router/offers/offers-profile-router.ts @@ -4,7 +4,7 @@ import * as trpc from '@trpc/server'; import { createRouter } from '../context'; -import type { OffersProfile } from '~/types/offers-profile'; +import type { OffersProfile } from '~/types/offers'; const valuation = z.object({ currency: z.string(), @@ -19,33 +19,37 @@ const company = z.object({ logoUrl: z.string().nullish(), name: z.string(), slug: z.string(), - updatedAt: z.date() -}) + updatedAt: z.date(), +}); const offer = z.object({ - OffersFullTime: z.object({ - baseSalary: valuation.nullish(), - baseSalaryId: z.string().nullish(), - bonus: valuation.nullish(), - bonusId: z.string().nullish(), - id: z.string().optional(), - level: z.string().nullish(), - specialization: z.string(), - stocks: valuation.nullish(), - stocksId: z.string().nullish(), - title: z.string(), - totalCompensation: valuation.nullish(), - totalCompensationId: z.string().nullish(), - }).nullish(), - OffersIntern: z.object({ - id: z.string().optional(), - internshipCycle: z.string().nullish(), - monthlySalary: valuation.nullish(), - specialization: z.string(), - startYear: z.number().nullish(), - title: z.string(), - totalCompensation: valuation.nullish(), // Full time - }).nullish(), + OffersFullTime: z + .object({ + baseSalary: valuation.nullish(), + baseSalaryId: z.string().nullish(), + bonus: valuation.nullish(), + bonusId: z.string().nullish(), + id: z.string().optional(), + level: z.string().nullish(), + specialization: z.string(), + stocks: valuation.nullish(), + stocksId: z.string().nullish(), + title: z.string(), + totalCompensation: valuation.nullish(), + totalCompensationId: z.string().nullish(), + }) + .nullish(), + OffersIntern: z + .object({ + id: z.string().optional(), + internshipCycle: z.string().nullish(), + monthlySalary: valuation.nullish(), + specialization: z.string(), + startYear: z.number().nullish(), + title: z.string(), + totalCompensation: valuation.nullish(), // Full time + }) + .nullish(), comments: z.string().nullish(), company: company.nullish(), companyId: z.string(), @@ -72,7 +76,7 @@ const experience = z.object({ specialization: z.string().nullish(), title: z.string().nullish(), totalCompensation: valuation.nullish(), - totalCompensationId: z.string().nullish() + totalCompensationId: z.string().nullish(), }); const education = z.object({ @@ -91,8 +95,8 @@ const reply = z.object({ messages: z.string().nullish(), profileId: z.string().nullish(), replyingToId: z.string().nullish(), - userId: z.string().nullish() -}) + userId: z.string().nullish(), +}); type WithIsEditable = T & { isEditable: boolean; @@ -144,7 +148,7 @@ export const offersProfileRouter = createRouter() include: { replies: true, replyingTo: true, - user: true + user: true, }, }, offers: { @@ -172,7 +176,7 @@ export const offersProfileRouter = createRouter() }); if (result) { - return exclude(computeIsEditable(result, input.token), 'editToken') + return exclude(computeIsEditable(result, input.token), 'editToken'); } throw new trpc.TRPCError({ @@ -389,7 +393,8 @@ export const offersProfileRouter = createRouter() title: x.OffersFullTime.title, totalCompensation: { create: { - currency: x.OffersFullTime.totalCompensation?.currency, + currency: + x.OffersFullTime.totalCompensation?.currency, value: x.OffersFullTime.totalCompensation?.value, }, }, @@ -493,7 +498,7 @@ export const offersProfileRouter = createRouter() backgroundId: z.string().optional(), domain: z.string(), id: z.string().optional(), - yoe: z.number() + yoe: z.number(), }), ), totalYoe: z.number(), @@ -505,7 +510,7 @@ export const offersProfileRouter = createRouter() offers: z.array(offer), profileName: z.string(), token: z.string(), - userId: z.string().nullish() + userId: z.string().nullish(), }), async resolve({ ctx, input }) { const profileToUpdate = await ctx.prisma.offersProfile.findFirst({ @@ -522,17 +527,17 @@ export const offersProfileRouter = createRouter() }, where: { id: input.id, - } + }, }); await ctx.prisma.offersBackground.update({ data: { - totalYoe: input.background.totalYoe + totalYoe: input.background.totalYoe, }, where: { - id: input.background.id - } - }) + id: input.background.id, + }, + }); for (const edu of input.background.educations) { if (edu.id) { @@ -545,27 +550,26 @@ export const offersProfileRouter = createRouter() type: edu.type, }, where: { - id: edu.id - } - }) + id: edu.id, + }, + }); } else { await ctx.prisma.offersBackground.update({ data: { educations: { - create: - { + create: { endDate: edu.endDate, field: edu.field, school: edu.school, startDate: edu.startDate, type: edu.type, - } - } + }, + }, }, where: { - id: input.background.id - } - }) + id: input.background.id, + }, + }); } } @@ -579,9 +583,9 @@ export const offersProfileRouter = createRouter() specialization: exp.specialization, }, where: { - id: exp.id - } - }) + id: exp.id, + }, + }); if (exp.monthlySalary) { await ctx.prisma.offersCurrency.update({ @@ -590,9 +594,9 @@ export const offersProfileRouter = createRouter() value: exp.monthlySalary.value, }, where: { - id: exp.monthlySalary.id - } - }) + id: exp.monthlySalary.id, + }, + }); } if (exp.totalCompensation) { @@ -602,12 +606,16 @@ export const offersProfileRouter = createRouter() value: exp.totalCompensation.value, }, where: { - id: exp.totalCompensation.id - } - }) + id: exp.totalCompensation.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) { await ctx.prisma.offersBackground.update({ data: { @@ -630,12 +638,12 @@ export const offersProfileRouter = createRouter() }, }, }, - } + }, }, where: { - id: input.background.id - } - }) + id: input.background.id, + }, + }); } else { await ctx.prisma.offersBackground.update({ data: { @@ -652,16 +660,15 @@ export const offersProfileRouter = createRouter() value: exp.totalCompensation?.value, }, }, - } - } + }, + }, }, where: { - id: input.background.id - } - }) + id: input.background.id, + }, + }); } - } - else if ( + } else if ( exp.jobType === 'INTERN' && exp.monthlySalary?.currency !== undefined && exp.monthlySalary.value !== undefined @@ -686,13 +693,13 @@ export const offersProfileRouter = createRouter() }, specialization: exp.specialization, title: exp.title, - } - } + }, + }, }, where: { - id: input.background.id - } - }) + id: input.background.id, + }, + }); } else { await ctx.prisma.offersBackground.update({ data: { @@ -708,44 +715,42 @@ export const offersProfileRouter = createRouter() }, specialization: exp.specialization, title: exp.title, - } - } + }, + }, }, where: { - id: input.background.id - } - }) + id: input.background.id, + }, + }); } } } - } for (const yoe of input.background.specificYoes) { if (yoe.id) { await ctx.prisma.offersSpecificYoe.update({ data: { - ...yoe + ...yoe, }, where: { - id: yoe.id - } - }) + id: yoe.id, + }, + }); } else { await ctx.prisma.offersBackground.update({ data: { specificYoes: { - create: - { + create: { domain: yoe.domain, yoe: yoe.yoe, - } - } + }, + }, }, where: { - id: input.background.id - } - }) + id: input.background.id, + }, + }); } } @@ -760,42 +765,46 @@ export const offersProfileRouter = createRouter() negotiationStrategy: offerToUpdate.negotiationStrategy, }, 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({ data: { - jobType: offerToUpdate.jobType + jobType: offerToUpdate.jobType, }, where: { - id: offerToUpdate.id - } - }) + id: offerToUpdate.id, + }, + }); } if (offerToUpdate.OffersIntern?.monthlySalary) { await ctx.prisma.offersIntern.update({ data: { - internshipCycle: offerToUpdate.OffersIntern.internshipCycle ?? undefined, + internshipCycle: + offerToUpdate.OffersIntern.internshipCycle ?? undefined, specialization: offerToUpdate.OffersIntern.specialization, startYear: offerToUpdate.OffersIntern.startYear ?? undefined, title: offerToUpdate.OffersIntern.title, }, where: { id: offerToUpdate.OffersIntern.id, - } - }) + }, + }); await ctx.prisma.offersCurrency.update({ data: { currency: offerToUpdate.OffersIntern.monthlySalary.currency, - value: offerToUpdate.OffersIntern.monthlySalary.value + value: offerToUpdate.OffersIntern.monthlySalary.value, }, where: { - id: offerToUpdate.OffersIntern.monthlySalary.id - } - }) + id: offerToUpdate.OffersIntern.monthlySalary.id, + }, + }); } if (offerToUpdate.OffersFullTime?.totalCompensation) { @@ -807,54 +816,55 @@ export const offersProfileRouter = createRouter() }, where: { id: offerToUpdate.OffersFullTime.id, - } - }) + }, + }); if (offerToUpdate.OffersFullTime.baseSalary) { await ctx.prisma.offersCurrency.update({ data: { currency: offerToUpdate.OffersFullTime.baseSalary.currency, - value: offerToUpdate.OffersFullTime.baseSalary.value + value: offerToUpdate.OffersFullTime.baseSalary.value, }, where: { - id: offerToUpdate.OffersFullTime.baseSalary.id - } - }) + id: offerToUpdate.OffersFullTime.baseSalary.id, + }, + }); } if (offerToUpdate.OffersFullTime.bonus) { await ctx.prisma.offersCurrency.update({ data: { currency: offerToUpdate.OffersFullTime.bonus.currency, - value: offerToUpdate.OffersFullTime.bonus.value + value: offerToUpdate.OffersFullTime.bonus.value, }, where: { - id: offerToUpdate.OffersFullTime.bonus.id - } - }) + id: offerToUpdate.OffersFullTime.bonus.id, + }, + }); } if (offerToUpdate.OffersFullTime.stocks) { await ctx.prisma.offersCurrency.update({ data: { currency: offerToUpdate.OffersFullTime.stocks.currency, - value: offerToUpdate.OffersFullTime.stocks.value + value: offerToUpdate.OffersFullTime.stocks.value, }, where: { - id: offerToUpdate.OffersFullTime.stocks.id - } - }) + id: offerToUpdate.OffersFullTime.stocks.id, + }, + }); } await ctx.prisma.offersCurrency.update({ data: { - currency: offerToUpdate.OffersFullTime.totalCompensation.currency, - value: offerToUpdate.OffersFullTime.totalCompensation.value + currency: + offerToUpdate.OffersFullTime.totalCompensation.currency, + value: offerToUpdate.OffersFullTime.totalCompensation.value, }, where: { - id: offerToUpdate.OffersFullTime.totalCompensation.id - } - }) + id: offerToUpdate.OffersFullTime.totalCompensation.id, + }, + }); } } else { if ( - offerToUpdate.jobType === "INTERN" && + offerToUpdate.jobType === 'INTERN' && offerToUpdate.OffersIntern && offerToUpdate.OffersIntern.internshipCycle && offerToUpdate.OffersIntern.monthlySalary?.currency && @@ -867,14 +877,19 @@ export const offersProfileRouter = createRouter() create: { OffersIntern: { create: { - internshipCycle: offerToUpdate.OffersIntern.internshipCycle, + internshipCycle: + offerToUpdate.OffersIntern.internshipCycle, monthlySalary: { create: { - currency: offerToUpdate.OffersIntern.monthlySalary?.currency, - value: offerToUpdate.OffersIntern.monthlySalary?.value, + currency: + offerToUpdate.OffersIntern.monthlySalary + ?.currency, + value: + offerToUpdate.OffersIntern.monthlySalary?.value, }, }, - specialization: offerToUpdate.OffersIntern.specialization, + specialization: + offerToUpdate.OffersIntern.specialization, startYear: offerToUpdate.OffersIntern.startYear, title: offerToUpdate.OffersIntern.title, }, @@ -889,13 +904,13 @@ export const offersProfileRouter = createRouter() location: offerToUpdate.location, monthYearReceived: offerToUpdate.monthYearReceived, negotiationStrategy: offerToUpdate.negotiationStrategy, - } - } + }, + }, }, where: { id: input.id, - } - }) + }, + }); } if ( offerToUpdate.jobType === 'FULLTIME' && @@ -918,29 +933,39 @@ export const offersProfileRouter = createRouter() create: { baseSalary: { create: { - currency: offerToUpdate.OffersFullTime.baseSalary?.currency, - value: offerToUpdate.OffersFullTime.baseSalary?.value, + currency: + offerToUpdate.OffersFullTime.baseSalary + ?.currency, + value: + offerToUpdate.OffersFullTime.baseSalary?.value, }, }, bonus: { create: { - currency: offerToUpdate.OffersFullTime.bonus?.currency, + currency: + offerToUpdate.OffersFullTime.bonus?.currency, value: offerToUpdate.OffersFullTime.bonus?.value, }, }, level: offerToUpdate.OffersFullTime.level, - specialization: offerToUpdate.OffersFullTime.specialization, + specialization: + offerToUpdate.OffersFullTime.specialization, stocks: { create: { - currency: offerToUpdate.OffersFullTime.stocks?.currency, + currency: + offerToUpdate.OffersFullTime.stocks?.currency, value: offerToUpdate.OffersFullTime.stocks?.value, }, }, title: offerToUpdate.OffersFullTime.title, totalCompensation: { create: { - currency: offerToUpdate.OffersFullTime.totalCompensation?.currency, - value: offerToUpdate.OffersFullTime.totalCompensation?.value, + currency: + offerToUpdate.OffersFullTime.totalCompensation + ?.currency, + value: + offerToUpdate.OffersFullTime.totalCompensation + ?.value, }, }, }, @@ -955,13 +980,13 @@ export const offersProfileRouter = createRouter() location: offerToUpdate.location, monthYearReceived: offerToUpdate.monthYearReceived, negotiationStrategy: offerToUpdate.negotiationStrategy, - } - } + }, + }, }, where: { id: input.id, - } - }) + }, + }); } } } @@ -985,7 +1010,7 @@ export const offersProfileRouter = createRouter() include: { replies: true, replyingTo: true, - user: true + user: true, }, }, offers: { @@ -1013,7 +1038,7 @@ export const offersProfileRouter = createRouter() }); if (result) { - return exclude(computeIsEditable(result, input.token), 'editToken') + return exclude(computeIsEditable(result, input.token), 'editToken'); } throw new trpc.TRPCError({ @@ -1036,9 +1061,9 @@ export const offersProfileRouter = createRouter() }), async resolve({ ctx, input }) { const profile = await ctx.prisma.offersProfile.findFirst({ - where: { - id: input.profileId, - }, + where: { + id: input.profileId, + }, }); const profileEditToken = profile?.editToken; @@ -1048,25 +1073,25 @@ export const offersProfileRouter = createRouter() data: { user: { connect: { - id: input.userId - } - } + id: input.userId, + }, + }, }, where: { - id: input.profileId - } - }) + id: input.profileId, + }, + }); return { id: updated.id, profileName: updated.profileName, - userId: updated.userId - } + userId: updated.userId, + }; } throw new trpc.TRPCError({ code: 'UNAUTHORIZED', message: 'Invalid token.', }); - } + }, }); diff --git a/apps/portal/src/types/offers-profile.d.ts b/apps/portal/src/types/offers-profile.d.ts deleted file mode 100644 index cc431184..00000000 --- a/apps/portal/src/types/offers-profile.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -export type OffersProfile = { - background?: Background | null; - createdAt: Date; -// Discussions: Array; - editToken: string; - id: string; - offers: Array; - profileName: string; - userId?: string | null; -}; - -export type Background = { - educations: Array; - experiences: Array; - id: string; - offersProfileId: string; - specificYoes: Array; - 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?; - replyingTo: Discussion?; - replyingToId: string | null; - user: User?; - userId: string | null; -} - -export type User = { - email: string?; - emailVerified: Date?; - id: string; - image: string?; - name: string?; -} \ No newline at end of file diff --git a/apps/portal/src/types/offers.d.ts b/apps/portal/src/types/offers.d.ts new file mode 100644 index 00000000..578c8135 --- /dev/null +++ b/apps/portal/src/types/offers.d.ts @@ -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; + profileName: string; +}; + +export type Background = { + educations: Array; + experiences: Array; + id: string; + specificYoes: Array; + 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?; + replyingToId: string?; + user: User?; +}; + +export type User = { + email: string?; + emailVerified: Date?; + id: string; + image: string?; + name: string?; +}; + +export type GetOffersResponse = { + data: Array; + 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; +}; + +export type OffersAnalysis = { + companyAnalysis: Array; + id: string; + overallAnalysis: Analysis; + overallHighestOffer: AnalysisHighestOffer; + profileId: string; +}; + +export type Analysis = { + noOfOffers: number; + percentile: number; + topPercentileOffers: Array; +}; + +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; + profileName: string; + specialization: string; + title: string; + totalYoe: number; +};