dont allow user to book a past date

pull/322/head
femyeda 2021-06-28 19:39:08 -05:00
parent f853865600
commit d1bdac45eb
1 changed files with 11 additions and 1 deletions

View File

@ -66,6 +66,16 @@ const getLocationRequestFromIntegration = ({ location }: GetLocationRequestFromI
export default async function handler(req: NextApiRequest, res: NextApiResponse) { export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { user } = req.query; const { user } = req.query;
const isTimeInPast = (time) => {
return dayjs(time).isBefore(new Date(), "day");
};
if (isTimeInPast(req.body.start)) {
return res
.status(400)
.json({ errorCode: "BookingDateInPast", message: "Attempting to create a meeting in the past." });
}
const currentUser = await prisma.user.findFirst({ const currentUser = await prisma.user.findFirst({
where: { where: {
username: user, username: user,
@ -170,7 +180,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}); });
// TODO isAvailable was throwing an error // TODO isAvailable was throwing an error
const isAvailableToBeBooked = true;//isAvailable(commonAvailability, req.body.start, selectedEventType.length); const isAvailableToBeBooked = true; //isAvailable(commonAvailability, req.body.start, selectedEventType.length);
if (!isAvailableToBeBooked) { if (!isAvailableToBeBooked) {
return res.status(400).json({ message: `${currentUser.name} is unavailable at this time.` }); return res.status(400).json({ message: `${currentUser.name} is unavailable at this time.` });