Cleaned up loading the availability schedule

This commit is contained in:
Alex van Andel 2021-06-16 22:50:29 +00:00
parent 9d5186f1e3
commit e3dbc52676

View file

@ -377,6 +377,7 @@ export async function getServerSideProps(context) {
timeZone: true, timeZone: true,
startTime: true, startTime: true,
endTime: true, endTime: true,
availability: true,
} }
}); });
@ -392,29 +393,19 @@ export async function getServerSideProps(context) {
length: true, length: true,
hidden: true, hidden: true,
locations: true, locations: true,
availability: true,
} }
}); });
let schedules = await prisma.schedule.findMany({ const getAvailability = (providesAvailability) => (
where: { providesAvailability.availability && providesAvailability.availability.length
eventTypeId: parseInt(context.query.type), ) ? providesAvailability.availability : null;
},
});
if (!schedules.length) { const schedules = getAvailability(eventType) || getAvailability(user) || [ {
schedules = await prisma.schedule.findMany({
where: {
userId: user.id,
},
});
if (!schedules.length) {
schedules.push({
days: [ 1, 2, 3, 4, 5, 6, 7 ], days: [ 1, 2, 3, 4, 5, 6, 7 ],
startTime: user.startTime, startTime: user.startTime,
length: user.endTime >= 1440 ? 1439 : user.endTime, length: user.endTime >= 1440 ? 1439 : user.endTime,
}); } ];
}
}
return { return {
props: { props: {