diff --git a/src/controllers/userController.ts b/src/controllers/userController.ts index 0bcd8c1..81bead8 100644 --- a/src/controllers/userController.ts +++ b/src/controllers/userController.ts @@ -10,7 +10,6 @@ import { CALENDAR_MAX_FUTURE_BOOKING_DAYS, CALENDAR_MAX_SERVICE_DURATION, CALENDAR_MIN_EARLIEST_BOOKING_TIME, - CALENDAR_USING_PRIMARY_CALENDAR, Roles, } from "../utils/constants"; import { @@ -214,7 +213,7 @@ export async function GetUser(req: Request, res: Response) { where: { user_id: session.user_id, }, - attributes: ["user_id", "username"], + attributes: ["user_id", "username", "store_id"], }); if (!user) { @@ -228,6 +227,22 @@ export async function GetUser(req: Request, res: Response) { attributes: ["store_id", "name"], }); + // if user is not a store master, then check if user is a worker + if (!stores || stores.length === 0) { + const store = await Store.findOne({ + where: { + store_id: user.store_id, + }, + attributes: ["store_id", "name"], + }); + + if (!store) { + return res.status(401).send({ err: "unauthorized" }); + } + + stores.push(store); + } + res.status(200).send({ user, stores }); } catch (error) { logger.error(error);