mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-28 04:33:42 +08:00
[offer][feat] add isSaved feature to get profile endpoint
This commit is contained in:
@ -527,8 +527,10 @@ export const profileDtoMapper = (
|
||||
offersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null;
|
||||
}
|
||||
>;
|
||||
user: User | null;
|
||||
},
|
||||
inputToken: string | undefined,
|
||||
inputUserId: string | null | undefined
|
||||
) => {
|
||||
const profileDto: Profile = {
|
||||
analysis: profileAnalysisDtoMapper(profile.analysis),
|
||||
@ -536,6 +538,7 @@ export const profileDtoMapper = (
|
||||
editToken: null,
|
||||
id: profile.id,
|
||||
isEditable: false,
|
||||
isSaved: false,
|
||||
offers: profile.offers.map((offer) => profileOfferDtoMapper(offer)),
|
||||
profileName: profile.profileName,
|
||||
};
|
||||
@ -543,6 +546,20 @@ export const profileDtoMapper = (
|
||||
if (inputToken === profile.editToken) {
|
||||
profileDto.editToken = profile.editToken ?? null;
|
||||
profileDto.isEditable = true;
|
||||
|
||||
const users = profile.user
|
||||
|
||||
// TODO: BRYANN UNCOMMENT THIS ONCE U CHANGE THE SCHEMA
|
||||
// for (let i = 0; i < users.length; i++) {
|
||||
// if (users[i].id === inputUserId) {
|
||||
// profileDto.isSaved = true
|
||||
// }
|
||||
// }
|
||||
|
||||
// TODO: REMOVE THIS ONCE U CHANGE THE SCHEMA
|
||||
if (users?.id === inputUserId) {
|
||||
profileDto.isSaved = true
|
||||
}
|
||||
}
|
||||
|
||||
return profileDto;
|
||||
|
@ -106,6 +106,7 @@ export const offersProfileRouter = createRouter()
|
||||
input: z.object({
|
||||
profileId: z.string(),
|
||||
token: z.string().optional(),
|
||||
userId: z.string().nullish(),
|
||||
}),
|
||||
async resolve({ ctx, input }) {
|
||||
const result = await ctx.prisma.offersProfile.findFirst({
|
||||
@ -228,6 +229,7 @@ export const offersProfileRouter = createRouter()
|
||||
},
|
||||
},
|
||||
},
|
||||
user: true,
|
||||
},
|
||||
where: {
|
||||
id: input.profileId,
|
||||
@ -235,7 +237,7 @@ export const offersProfileRouter = createRouter()
|
||||
});
|
||||
|
||||
if (result) {
|
||||
return profileDtoMapper(result, input.token);
|
||||
return profileDtoMapper(result, input.token, input.userId);
|
||||
}
|
||||
|
||||
throw new trpc.TRPCError({
|
||||
|
1
apps/portal/src/types/offers.d.ts
vendored
1
apps/portal/src/types/offers.d.ts
vendored
@ -6,6 +6,7 @@ export type Profile = {
|
||||
editToken: string?;
|
||||
id: string;
|
||||
isEditable: boolean;
|
||||
isSaved: boolean;
|
||||
offers: Array<ProfileOffer>;
|
||||
profileName: string;
|
||||
};
|
||||
|
Reference in New Issue
Block a user