diff --git a/src/controllers/calendarController.ts b/src/controllers/calendarController.ts index b3c1b71..9c7eaa3 100644 --- a/src/controllers/calendarController.ts +++ b/src/controllers/calendarController.ts @@ -31,3 +31,45 @@ export async function GetStoreId(req: Request, res: Response) { res.status(500).send({ err: "invalid request" }); } } + +export async function GetCalendarSettings(req: Request, res: Response) { + try { + const userSession = await getUserSession(req); + + if (!userSession) { + return res.status(401).send({ err: "unauthorized" }); + } + + // check if user has a store + + const store = await Store.findOne({ + where: { + owner_user_id: userSession.user_id, + }, + attributes: [ + "calendar_max_future_booking_days", + "calendar_min_earliest_booking_time", + "calendar_max_service_duration", + ], + }); + + if (!store) { + return res.status(401).send({ err: "unauthorized" }); + } + + console.log("test", req.user); + + res.status(200).send({ + settings: { + calendar_max_future_booking_days: + store.calendar_max_future_booking_days, + calendar_min_earliest_booking_time: + store.calendar_min_earliest_booking_time, + calendar_max_service_duration: store.calendar_max_service_duration, + }, + }); + } catch (error) { + logger.error(error); + res.status(500).send({ err: "invalid request" }); + } +} diff --git a/src/routes/calendarRoutes.ts b/src/routes/calendarRoutes.ts index 6579c6f..5e95fd2 100644 --- a/src/routes/calendarRoutes.ts +++ b/src/routes/calendarRoutes.ts @@ -32,5 +32,6 @@ router.get( ); router.get("/store", calendarController.GetStoreId); +router.get("/settings", calendarController.GetCalendarSettings); export default router;