mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-28 12:43:12 +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;
|
offersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
user: User | null;
|
||||||
},
|
},
|
||||||
inputToken: string | undefined,
|
inputToken: string | undefined,
|
||||||
|
inputUserId: string | null | undefined
|
||||||
) => {
|
) => {
|
||||||
const profileDto: Profile = {
|
const profileDto: Profile = {
|
||||||
analysis: profileAnalysisDtoMapper(profile.analysis),
|
analysis: profileAnalysisDtoMapper(profile.analysis),
|
||||||
@ -536,6 +538,7 @@ export const profileDtoMapper = (
|
|||||||
editToken: null,
|
editToken: null,
|
||||||
id: profile.id,
|
id: profile.id,
|
||||||
isEditable: false,
|
isEditable: false,
|
||||||
|
isSaved: false,
|
||||||
offers: profile.offers.map((offer) => profileOfferDtoMapper(offer)),
|
offers: profile.offers.map((offer) => profileOfferDtoMapper(offer)),
|
||||||
profileName: profile.profileName,
|
profileName: profile.profileName,
|
||||||
};
|
};
|
||||||
@ -543,6 +546,20 @@ export const profileDtoMapper = (
|
|||||||
if (inputToken === profile.editToken) {
|
if (inputToken === profile.editToken) {
|
||||||
profileDto.editToken = profile.editToken ?? null;
|
profileDto.editToken = profile.editToken ?? null;
|
||||||
profileDto.isEditable = true;
|
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;
|
return profileDto;
|
||||||
|
@ -106,6 +106,7 @@ export const offersProfileRouter = createRouter()
|
|||||||
input: z.object({
|
input: z.object({
|
||||||
profileId: z.string(),
|
profileId: z.string(),
|
||||||
token: z.string().optional(),
|
token: z.string().optional(),
|
||||||
|
userId: z.string().nullish(),
|
||||||
}),
|
}),
|
||||||
async resolve({ ctx, input }) {
|
async resolve({ ctx, input }) {
|
||||||
const result = await ctx.prisma.offersProfile.findFirst({
|
const result = await ctx.prisma.offersProfile.findFirst({
|
||||||
@ -228,6 +229,7 @@ export const offersProfileRouter = createRouter()
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
user: true,
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
id: input.profileId,
|
id: input.profileId,
|
||||||
@ -235,7 +237,7 @@ export const offersProfileRouter = createRouter()
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
return profileDtoMapper(result, input.token);
|
return profileDtoMapper(result, input.token, input.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new trpc.TRPCError({
|
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?;
|
editToken: string?;
|
||||||
id: string;
|
id: string;
|
||||||
isEditable: boolean;
|
isEditable: boolean;
|
||||||
|
isSaved: boolean;
|
||||||
offers: Array<ProfileOffer>;
|
offers: Array<ProfileOffer>;
|
||||||
profileName: string;
|
profileName: string;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user