From 34f5f5f83f0f4a66392ff17757159b4834689eb8 Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung Date: Thu, 6 Oct 2022 10:55:14 -0400 Subject: [PATCH] Pass userId as single value or array --- pages/api/event-types/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index c46979385d..04445a709c 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -45,8 +45,14 @@ async function createOrlistAllEventTypes( }); } else { const data = await prisma.eventType.findMany({ - where: { userId: isAdmin && body.userId ? body.userId : userId }, + where: { + ...(Array.isArray(body.userId) + ? { userId: { in: body.userId } } + : { userId: body.userId || userId }), + }, + ...(Array.isArray(body.userId) && { orderBy: { userId: "asc" } }), }); + console.log("🚀 ~ file: index.ts ~ line 50 ~ data", data); const event_types = data.map((eventType) => schemaEventTypeReadPublic.parse(eventType)); if (event_types) res.status(200).json({ event_types }); }