Updated team to also use getWorkingHours (#1188)

pull/1186/head^2
Alex van Andel 2021-11-18 10:20:48 +00:00 committed by GitHub
parent e0d1b6b5ea
commit d6dd13a9d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 20 deletions

View File

@ -1,6 +1,7 @@
import { GetServerSidePropsContext } from "next";
import { asStringOrNull } from "@lib/asStringOrNull";
import { getWorkingHours } from "@lib/availability";
import prisma from "@lib/prisma";
import { inferSSRProps } from "@lib/types/inferSSRProps";
@ -74,26 +75,12 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
const [eventType] = team.eventTypes;
type Availability = typeof eventType["availability"];
const getWorkingHours = (availability: Availability) =>
availability?.length
? availability.map((schedule) => ({
...schedule,
startTime: schedule.startTime.getUTCHours() * 60 + schedule.startTime.getUTCMinutes(),
endTime: schedule.endTime.getUTCHours() * 60 + schedule.endTime.getUTCMinutes(),
}))
: null;
const workingHours =
getWorkingHours(eventType.availability) ||
[
{
days: [0, 1, 2, 3, 4, 5, 6],
startTime: 0,
endTime: 1440,
},
].filter((availability): boolean => typeof availability["days"] !== "undefined");
workingHours.sort((a, b) => a.startTime - b.startTime);
const workingHours = getWorkingHours(
{
timeZone: eventType.timeZone || undefined,
},
eventType.availability
);
const eventTypeObject = Object.assign({}, eventType, {
periodStartDate: eventType.periodStartDate?.toString() ?? null,