check
parent
e8f2c69183
commit
42cb2f1773
|
@ -10,7 +10,6 @@ import {
|
||||||
CALENDAR_MAX_FUTURE_BOOKING_DAYS,
|
CALENDAR_MAX_FUTURE_BOOKING_DAYS,
|
||||||
CALENDAR_MAX_SERVICE_DURATION,
|
CALENDAR_MAX_SERVICE_DURATION,
|
||||||
CALENDAR_MIN_EARLIEST_BOOKING_TIME,
|
CALENDAR_MIN_EARLIEST_BOOKING_TIME,
|
||||||
CALENDAR_USING_PRIMARY_CALENDAR,
|
|
||||||
Roles,
|
Roles,
|
||||||
} from "../utils/constants";
|
} from "../utils/constants";
|
||||||
import {
|
import {
|
||||||
|
@ -214,7 +213,7 @@ export async function GetUser(req: Request, res: Response) {
|
||||||
where: {
|
where: {
|
||||||
user_id: session.user_id,
|
user_id: session.user_id,
|
||||||
},
|
},
|
||||||
attributes: ["user_id", "username"],
|
attributes: ["user_id", "username", "store_id"],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
@ -228,6 +227,22 @@ export async function GetUser(req: Request, res: Response) {
|
||||||
attributes: ["store_id", "name"],
|
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 });
|
res.status(200).send({ user, stores });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error);
|
logger.error(error);
|
||||||
|
|
Loading…
Reference in New Issue