main
alex 2024-01-20 23:42:57 +01:00
parent e8f2c69183
commit 42cb2f1773
1 changed files with 17 additions and 2 deletions

View File

@ -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);