From d84f54f28af1ba425ddd8649f164ac7983be48d4 Mon Sep 17 00:00:00 2001 From: supalarry Date: Thu, 26 Oct 2023 12:13:02 +0200 Subject: [PATCH] fix: kysely query 2 --- .../trpc/server/routers/viewer/slots/util.ts | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/trpc/server/routers/viewer/slots/util.ts b/packages/trpc/server/routers/viewer/slots/util.ts index b011fb528c..1320576b71 100644 --- a/packages/trpc/server/routers/viewer/slots/util.ts +++ b/packages/trpc/server/routers/viewer/slots/util.ts @@ -319,7 +319,11 @@ export async function getEventType( // note(Lauris): Availability startTime and endTime have DateTime in Prisma schema, // but in DB only hh:mm:ss are stored e.g. "09:00:00". Prisma transforms data as follows: - eventType?.users.forEach((user) => { + if (!eventType) { + return null; + } + + eventType.users.forEach((user) => { user.schedules.forEach((schedule) => { schedule.availability.forEach((availability) => { availability.startTime = new Date(`1970-01-01T${availability.startTime}.000Z`); @@ -328,9 +332,19 @@ export async function getEventType( }); }); - if (!eventType) { - return null; - } + eventType.hosts.forEach((host) => { + host.user?.schedules.forEach((schedule) => { + schedule.availability.forEach((availability) => { + availability.startTime = new Date(`1970-01-01T${availability.startTime}.000Z`); + availability.endTime = new Date(`1970-01-01T${availability.endTime}.000Z`); + }); + }); + }); + + eventType.schedule?.availability.forEach((entry) => { + entry.startTime = new Date(`1970-01-01T${entry.startTime}.000Z`); + entry.endTime = new Date(`1970-01-01T${entry.endTime}.000Z`); + }); return { ...eventType,