[offers][chore] add editToken check for backend

pull/360/head
Stuart Long Chay Boon 2 years ago
parent 0822bee33b
commit 34c8c7d605

@ -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([ const data = trpc.useQuery([
`offers.profile.listOne`, `offers.profile.listOne`,
{ {
profileId, profileId,
token: "6c8d53530163bb765c42bd9f441aa7e345f607c4e1892edbc64e5bbbbe7ee916"
}, },
]); ]);

@ -3,6 +3,7 @@ import { z } from 'zod';
import { Prisma } from '@prisma/client'; import { Prisma } from '@prisma/client';
import { createRouter } from './context'; import { createRouter } from './context';
import type { offersProfile } from '../../types/offers-profile';
const valuation = z.object({ const valuation = z.object({
currency: z.string(), currency: z.string(),
@ -53,54 +54,70 @@ const education = z.object({
export const offersProfileRouter = createRouter() export const offersProfileRouter = createRouter()
.query('listOne', { .query('listOne', {
input: z.object({ input: z.object({
profileId: z.string(), profileId: z.string(),
token: z.string().optional()
}), }),
async resolve({ ctx, input }) { async resolve({ ctx, input }) {
return await ctx.prisma.offersProfile.findFirst({ const result = await ctx.prisma.offersProfile.findFirst({
include: { include: {
background: { background: {
include: { include: {
educations: true, educations: true,
experiences: { experiences: {
include: { include: {
company: true, company: true,
monthlySalary: true, monthlySalary: true,
totalCompensation: true, totalCompensation: true,
}, },
}, },
specificYoes: true, specificYoes: true,
}, },
}, },
discussion: { discussion: {
include: { include: {
replies: true, replies: true,
replyingTo: true, replyingTo: true,
}, },
}, },
offers: { offers: {
include: { include: {
OffersFullTime: { OffersFullTime: {
include: { include: {
baseSalary: true, baseSalary: true,
bonus: true, bonus: true,
stocks: true, stocks: true,
totalCompensation: true, totalCompensation: true,
}, },
}, },
OffersIntern: { OffersIntern: {
include: { include: {
monthlySalary: true, monthlySalary: true,
}, },
},
company: true,
},
},
}, },
company: true, where: {
}, id: input.profileId,
}, }
}, });
where: { // Extend the T generic with the fullName attribute
id: input.profileId, type WithIsEditable<T> = T & {
}, isEditable: boolean
}); }
},
// Take objects that satisfy FirstLastName and computes a full name
function computeIsEditable(
profileInput: offersProfile
): WithIsEditable<offersProfile> {
return {
...profileInput,
isEditable: profileInput["editToken" as keyof typeof profileInput] === input.token,
}
}
return result ? computeIsEditable(result) : result;
},
}) })
.mutation('create', { .mutation('create', {
input: z.object({ input: z.object({
@ -334,7 +351,6 @@ export const offersProfileRouter = createRouter()
}, },
}, },
}); });
// TODO: add analysis to profile object then return // TODO: add analysis to profile object then return
return profile; return profile;
}, },

@ -0,0 +1,113 @@
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 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;
}
Loading…
Cancel
Save