From 372e1882287202156eb78287ba0fb6ea1d8dd020 Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung Date: Thu, 6 Oct 2022 09:55:34 -0400 Subject: [PATCH] Pass userId as a single value or an array --- pages/api/schedules/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pages/api/schedules/index.ts b/pages/api/schedules/index.ts index 0a35657d09..29b5577c51 100644 --- a/pages/api/schedules/index.ts +++ b/pages/api/schedules/index.ts @@ -32,7 +32,13 @@ async function createOrlistAllSchedules( * description: No schedules were found */ const data = await prisma.schedule.findMany({ - where: { userId: body.userId && isAdmin ? body.userId : userId }, + // where: { userId: body.userId && isAdmin ? body.userId : userId }, + where: { + ...(Array.isArray(body.userId) + ? { userId: { in: body.userId } } + : { userId: body.userId || userId }), + }, + ...(Array.isArray(body.userId) && { orderBy: { userId: "asc" } }), }); const schedules = data.map((schedule) => schemaSchedulePublic.parse(schedule)); if (schedules) res.status(200).json({ schedules });