[offer][feat] add isSaved feature to get profile endpoint

pull/450/head
Stuart Long Chay Boon 2 years ago
parent 04ae318d69
commit 288a585c1a

@ -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({

@ -6,6 +6,7 @@ export type Profile = {
editToken: string?;
id: string;
isEditable: boolean;
isSaved: boolean;
offers: Array<ProfileOffer>;
profileName: string;
};

Loading…
Cancel
Save