From 84f04f5aba9a0f1e0a77924090aa847ce4533ce5 Mon Sep 17 00:00:00 2001 From: Brandon Egger Date: Fri, 17 Mar 2023 01:56:09 -0500 Subject: [PATCH] add filtering for enums --- src/server/api/routers/auditoryResources.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/server/api/routers/auditoryResources.ts b/src/server/api/routers/auditoryResources.ts index 3134e6d..c7d71fc 100644 --- a/src/server/api/routers/auditoryResources.ts +++ b/src/server/api/routers/auditoryResources.ts @@ -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), + } + } + }) }), });