v1.0.0
This commit is contained in:
@@ -5,62 +5,91 @@ const authenticate = (req, res, next) => {
|
||||
if (!uuid) return res.status(401).json({ error: "Unauthorized" });
|
||||
|
||||
db.get(`
|
||||
SELECT sheeps.*, administrators.* FROM administrators JOIN sheeps ON sheeps.id = administrators.sheep_id WHERE administrators.uuid = ?`,
|
||||
SELECT
|
||||
sheeps.*,
|
||||
possibilities.can_add_sheeps AS can_add_sheeps,
|
||||
possibilities.can_view_sheeps AS can_view_sheeps,
|
||||
possibilities.can_add_territory AS can_add_territory,
|
||||
possibilities.can_view_territory AS can_view_territory,
|
||||
possibilities.can_manager_territory AS can_manager_territory,
|
||||
possibilities.can_add_stand AS can_add_stand,
|
||||
possibilities.can_view_stand AS can_view_stand,
|
||||
possibilities.can_manager_stand AS can_manager_stand,
|
||||
possibilities.can_add_schedule AS can_add_schedule,
|
||||
possibilities.can_view_schedule AS can_view_schedule
|
||||
FROM
|
||||
sheeps
|
||||
LEFT JOIN
|
||||
possibilities ON possibilities.sheep_id = sheeps.id
|
||||
WHERE
|
||||
sheeps.uuid_manager = ?`,
|
||||
[uuid],
|
||||
(err, administrator) => {
|
||||
if (administrator) {
|
||||
req.sheepId = administrator.sheep_id;
|
||||
req.sheepRole = 'administrator';
|
||||
req.group_id = administrator.group_id;
|
||||
req.sheepName = administrator.name;
|
||||
req.can_view_schedule = administrator.can_view_schedule;
|
||||
req.can_view_stand = administrator.can_view_stand;
|
||||
req.can_view_territory = administrator.can_view_territory;
|
||||
(err, moderator) => {
|
||||
if (moderator) {
|
||||
req.sheepId = moderator.id;
|
||||
req.sheepName = moderator.name;
|
||||
req.group_id = moderator.group_id;
|
||||
req.mode = Number(moderator.mode);
|
||||
req.possibilities = {
|
||||
can_add_sheeps: moderator.can_add_sheeps == 1 ? true : false,
|
||||
can_view_sheeps: moderator.can_view_sheeps == 1 ? true : false,
|
||||
can_add_territory: moderator.can_add_territory == 1 ? true : false,
|
||||
can_view_territory: moderator.can_view_territory == 1 ? true : false,
|
||||
can_manager_territory: moderator.can_manager_territory == 1 ? true : false,
|
||||
can_add_stand: moderator.can_add_stand == 1 ? true : false,
|
||||
can_view_stand: moderator.can_view_stand == 1 ? true : false,
|
||||
can_manager_stand: moderator.can_manager_stand == 1 ? true : false,
|
||||
can_add_schedule: moderator.can_add_schedule == 1 ? true : false,
|
||||
can_view_schedule: moderator.can_view_schedule == 1 ? true : false
|
||||
}
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
db.get(`
|
||||
SELECT sheeps.*, moderators.* FROM moderators JOIN sheeps ON sheeps.id = moderators.sheep_id WHERE moderators.uuid = ?`,
|
||||
SELECT
|
||||
sheeps.*,
|
||||
possibilities.can_add_sheeps AS can_add_sheeps,
|
||||
possibilities.can_view_sheeps AS can_view_sheeps,
|
||||
possibilities.can_add_territory AS can_add_territory,
|
||||
possibilities.can_view_territory AS can_view_territory,
|
||||
possibilities.can_manager_territory AS can_manager_territory,
|
||||
possibilities.can_add_stand AS can_add_stand,
|
||||
possibilities.can_view_stand AS can_view_stand,
|
||||
possibilities.can_manager_stand AS can_manager_stand,
|
||||
possibilities.can_add_schedule AS can_add_schedule,
|
||||
possibilities.can_view_schedule AS can_view_schedule
|
||||
FROM
|
||||
sheeps
|
||||
LEFT JOIN
|
||||
possibilities ON possibilities.sheep_id = sheeps.id
|
||||
WHERE
|
||||
sheeps.uuid = ?`,
|
||||
[uuid],
|
||||
(err, moderator) => {
|
||||
if (moderator) {
|
||||
req.sheepId = moderator.sheep_id;
|
||||
req.sheepRole = 'moderator';
|
||||
req.moderator = {
|
||||
"id": moderator.moderators_id ? moderator.moderators_id : false,
|
||||
"can_add_sheeps": moderator.can_add_sheeps == 1 ? true : false,
|
||||
"can_add_territory": moderator.can_add_territory == 1 ? true : false,
|
||||
"can_manager_territory": moderator.can_manager_territory == 1 ? true : false,
|
||||
"can_add_stand": moderator.can_add_stand == 1 ? true : false,
|
||||
"can_manager_stand": moderator.can_manager_stand == 1 ? true : false,
|
||||
"can_add_schedule": moderator.can_add_schedule == 1 ? true : false
|
||||
(err, sheep) => {
|
||||
if (sheep) {
|
||||
req.sheepId = sheep.id;
|
||||
req.sheepName = sheep.name;
|
||||
req.group_id = sheep.group_id;
|
||||
req.uuid_manager = null;
|
||||
req.mode = 0;
|
||||
req.possibilities = {
|
||||
can_add_sheeps: false,
|
||||
can_view_sheeps: false,
|
||||
can_add_territory: false,
|
||||
can_manager_territory: false,
|
||||
can_add_stand: false,
|
||||
can_manager_stand: false,
|
||||
can_add_schedule: false,
|
||||
can_view_territory: sheep.can_view_territory == 1 ? true : false,
|
||||
can_view_stand: sheep.can_view_stand == 1 ? true : false,
|
||||
can_view_schedule: sheep.can_view_schedule == 1 ? true : false
|
||||
}
|
||||
req.group_id = moderator.group_id;
|
||||
req.sheepName = moderator.name;
|
||||
req.can_view_schedule = moderator.can_view_schedule;
|
||||
req.can_view_stand = moderator.can_view_stand;
|
||||
req.can_view_territory = moderator.can_view_territory;
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
db.get(`SELECT sheeps.* FROM sheeps WHERE sheeps.uuid = ?`, [uuid], (err, sheep) => {
|
||||
if (sheep) {
|
||||
req.sheepId = sheep.id;
|
||||
req.sheepRole = 'sheep';
|
||||
req.group_id = sheep.group_id;
|
||||
req.sheepName = sheep.name;
|
||||
req.can_view_schedule = sheep.can_view_schedule;
|
||||
req.can_view_stand = sheep.can_view_stand;
|
||||
req.can_view_territory = sheep.can_view_territory;
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
return res.status(401).json({ error: "UUID not found" });
|
||||
}
|
||||
);
|
||||
return res.status(401).json({ error: "UUID not found" });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user