From 8f9a970fb63ac8a95fd0e9a4fdf810df6addc5af Mon Sep 17 00:00:00 2001 From: Agusti Fernandez Pardo Date: Fri, 27 May 2022 20:43:10 +0200 Subject: [PATCH] fix: moves event-types to find user including it's event-types --- pages/api/event-types/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pages/api/event-types/index.ts b/pages/api/event-types/index.ts index c3a7cc954f..610743baac 100644 --- a/pages/api/event-types/index.ts +++ b/pages/api/event-types/index.ts @@ -29,15 +29,17 @@ async function createOrlistAllEventTypes( * 404: * description: No event types were found */ - const data = await prisma.eventType - .findMany({ where: { userId } }) + const data = await prisma.user + .findUnique({ + where: { id: userId }, + rejectOnNotFound: true, + select: { eventTypes: true }, + }) .catch((error) => res.status(404).json({ message: "No event types were found", error })); - console.log("eventTypes:", data); - console.log("userId:", userId); // const event_types = data.map( // async (eventType) => await schemaEventTypeReadPublic.safeParseAsync(eventType) // ); - if (data) res.status(200).json({ event_types: data }); + if (data) res.status(200).json({ event_types: data.eventTypes }); else (error: Error) => res.status(404).json({