mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-31 06:03:55 +08:00
[offers][chore] add editToken check for backend
This commit is contained in:
@ -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(),
|
||||||
@ -54,9 +55,10 @@ 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: {
|
||||||
@ -98,8 +100,23 @@ export const offersProfileRouter = createRouter()
|
|||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
id: input.profileId,
|
id: input.profileId,
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
|
// Extend the T generic with the fullName attribute
|
||||||
|
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', {
|
||||||
@ -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;
|
||||||
},
|
},
|
||||||
|
113
apps/portal/src/types/offers-profile.d.ts
vendored
Normal file
113
apps/portal/src/types/offers-profile.d.ts
vendored
Normal file
@ -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;
|
||||||
|
}
|
Reference in New Issue
Block a user