diff --git a/apps/portal/src/pages/offers/testCreateProfile.tsx b/apps/portal/src/pages/offers/testCreateProfile.tsx index 8528cdac..fea8cdcc 100644 --- a/apps/portal/src/pages/offers/testCreateProfile.tsx +++ b/apps/portal/src/pages/offers/testCreateProfile.tsx @@ -126,11 +126,12 @@ function Test() { }); }; - const profileId = 'cl93qtuyc0000w3ideermqtcz'; // Remember to change this filed after testing deleting + const profileId = 'cl93tvejz00bei9qinzmjgy75'; // Remember to change this filed after testing deleting const data = trpc.useQuery([ `offers.profile.listOne`, { profileId, + token: "6c8d53530163bb765c42bd9f441aa7e345f607c4e1892edbc64e5bbbbe7ee916" }, ]); diff --git a/apps/portal/src/server/router/offers-profile-router.ts b/apps/portal/src/server/router/offers-profile-router.ts index aa4261e5..cdd01558 100644 --- a/apps/portal/src/server/router/offers-profile-router.ts +++ b/apps/portal/src/server/router/offers-profile-router.ts @@ -3,6 +3,7 @@ import { z } from 'zod'; import { Prisma } from '@prisma/client'; import { createRouter } from './context'; +import type { offersProfile } from '../../types/offers-profile'; const valuation = z.object({ currency: z.string(), @@ -53,54 +54,70 @@ const education = z.object({ export const offersProfileRouter = createRouter() .query('listOne', { input: z.object({ - profileId: z.string(), + profileId: z.string(), + token: z.string().optional() }), - async resolve({ ctx, input }) { - return await ctx.prisma.offersProfile.findFirst({ - include: { - background: { - include: { - educations: 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, - }, + async resolve({ ctx, input }) { + const result = await ctx.prisma.offersProfile.findFirst({ + include: { + background: { + include: { + educations: 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, + }, + }, }, - company: true, - }, - }, - }, - where: { - id: input.profileId, - }, - }); - }, + where: { + id: input.profileId, + } + }); + // Extend the T generic with the fullName attribute + type WithIsEditable = T & { + isEditable: boolean + } + + // Take objects that satisfy FirstLastName and computes a full name + function computeIsEditable( + profileInput: offersProfile + ): WithIsEditable { + return { + ...profileInput, + isEditable: profileInput["editToken" as keyof typeof profileInput] === input.token, + } + } + return result ? computeIsEditable(result) : result; + }, }) .mutation('create', { input: z.object({ @@ -334,7 +351,6 @@ export const offersProfileRouter = createRouter() }, }, }); - // TODO: add analysis to profile object then return return profile; }, diff --git a/apps/portal/src/types/offers-profile.d.ts b/apps/portal/src/types/offers-profile.d.ts new file mode 100644 index 00000000..0990612a --- /dev/null +++ b/apps/portal/src/types/offers-profile.d.ts @@ -0,0 +1,113 @@ +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 offers = { + OffersFullTime?: offersFullTime | null; + OffersIntern?: offersIntern | null; + comments?: string | null; + company: company; + companyId: string; + id: string; + jobType: string; + location: string; + monthYearReceived: string; + negotiationStrategy?: string | null; + offersFullTimeId?: string | null; + offersInternId?: string | null; + profileId: string; +} + +export type offersFullTime = { + baseSalary: valuation; + baseSalaryId: string; + bonus: valuation; + bonusId: string; + id: string; + level: string; + specialization: string; + stocks: valuation; + stocksId: string; + title?: string | null; + totalCompensation: valuation; + totalCompensationId: string; +} + +export type offersIntern = { + id: string; + internshipCycle: string; + monthlySalary: valuation; + monthlySalaryId: string; + specialization: string; + startYear: number; +} + +// TODO: fill in next time +export type discussion = { + id: string; +} \ No newline at end of file