[offers][fix] add check if admin for list endpoint

pull/553/head
Stuart Long Chay Boon 2 years ago
parent 55beb386e8
commit 75d7132409

@ -64,6 +64,20 @@ export const offerAdminRouter = createProtectedRouter().query('list', {
yoeMin: z.number().min(0).nullish(), yoeMin: z.number().min(0).nullish(),
}), }),
async resolve({ ctx, input }) { async resolve({ ctx, input }) {
const userId = ctx.session.user.id;
const adminAccount = await ctx.prisma.offersAdmin.findFirst({
where: {
userId
}
})
if (!adminAccount) {
throw new TRPCError({
code: 'UNAUTHORIZED',
message: 'Not an admin.',
});
}
const yoeRange = getYoeRange(input.yoeCategory); const yoeRange = getYoeRange(input.yoeCategory);
const yoeMin = input.yoeMin != null ? input.yoeMin : yoeRange?.minYoe; const yoeMin = input.yoeMin != null ? input.yoeMin : yoeRange?.minYoe;
const yoeMax = input.yoeMax != null ? input.yoeMax : yoeRange?.maxYoe; const yoeMax = input.yoeMax != null ? input.yoeMax : yoeRange?.maxYoe;

Loading…
Cancel
Save