add filtering for enums

This commit is contained in:
Brandon Egger 2023-03-17 01:56:09 -05:00
parent 3cc131c344
commit 84f04f5aba

View File

@ -32,8 +32,18 @@ export const auditoryResourceRouter = createTRPCRouter({
skill_levels: z.nativeEnum(SkillLevel).array().optional(),
skills: z.nativeEnum(Skill).array().optional(),
}))
.query(({ctx}) => {
.query(({ input, ctx}) => {
return ctx.prisma.auditoryResource.findMany();
return ctx.prisma.auditoryResource.findMany({
where: {
// ages: input.ages ? {min: 0, max: 100}, TODO: Make this so ranges work.
skill_levels: {
hasEvery: input.skill_levels ?? Object.values(SkillLevel),
},
skills: {
hasEvery: input.skills ?? Object.values(Skill),
}
}
})
}),
});