fix: moves event-types to find user including it's event-types

pull/9078/head
Agusti Fernandez Pardo 2022-05-27 20:43:10 +02:00
parent ed2f42fb01
commit 8f9a970fb6
1 changed files with 7 additions and 5 deletions

View File

@ -29,15 +29,17 @@ async function createOrlistAllEventTypes(
* 404: * 404:
* description: No event types were found * description: No event types were found
*/ */
const data = await prisma.eventType const data = await prisma.user
.findMany({ where: { userId } }) .findUnique({
where: { id: userId },
rejectOnNotFound: true,
select: { eventTypes: true },
})
.catch((error) => res.status(404).json({ message: "No event types were found", error })); .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( // const event_types = data.map(
// async (eventType) => await schemaEventTypeReadPublic.safeParseAsync(eventType) // 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 else
(error: Error) => (error: Error) =>
res.status(404).json({ res.status(404).json({