From d1bdac45eb2afe1a6e1916b0a4414b103bbd069e Mon Sep 17 00:00:00 2001 From: femyeda Date: Mon, 28 Jun 2021 19:39:08 -0500 Subject: [PATCH] dont allow user to book a past date --- pages/api/book/[user].ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pages/api/book/[user].ts b/pages/api/book/[user].ts index c6d41e0711..8fbd5791a6 100644 --- a/pages/api/book/[user].ts +++ b/pages/api/book/[user].ts @@ -66,6 +66,16 @@ const getLocationRequestFromIntegration = ({ location }: GetLocationRequestFromI export default async function handler(req: NextApiRequest, res: NextApiResponse) { 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({ where: { username: user, @@ -170,7 +180,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }); // 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) { return res.status(400).json({ message: `${currentUser.name} is unavailable at this time.` });