v1.0.0
This commit is contained in:
@@ -1,34 +1,27 @@
|
||||
const db = require("../config/db");
|
||||
|
||||
class AuthService {
|
||||
findUserByID(id, sheepRole) {
|
||||
findUserByID(id, mode) {
|
||||
return new Promise((res, rej) => {
|
||||
let sql = `
|
||||
SELECT
|
||||
sheeps.*,
|
||||
groups.group_number AS group_id,
|
||||
administrators.id AS administrators_id,
|
||||
administrators.uuid AS administrators_uuid,
|
||||
moderators.id AS moderators_id,
|
||||
moderators.uuid AS moderators_uuid,
|
||||
moderators.can_add_sheeps,
|
||||
moderators.can_add_territory,
|
||||
moderators.can_manager_territory,
|
||||
moderators.can_add_stand,
|
||||
moderators.can_manager_stand,
|
||||
moderators.can_add_schedule
|
||||
FROM
|
||||
sheeps
|
||||
LEFT JOIN
|
||||
groups ON groups.group_number = sheeps.group_id
|
||||
LEFT JOIN
|
||||
administrators ON administrators.sheep_id = sheeps.id
|
||||
LEFT JOIN
|
||||
moderators ON moderators.sheep_id = sheeps.id
|
||||
WHERE
|
||||
sheeps.id = ?
|
||||
LIMIT 1;
|
||||
`
|
||||
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.id = ?`;
|
||||
db.get(sql, [id], (err, sheep) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
@@ -38,40 +31,36 @@ class AuthService {
|
||||
return res(false);
|
||||
} else {
|
||||
let data = {
|
||||
"id": Number(sheep.id),
|
||||
"group_id": Number(sheep.group_id),
|
||||
"name": sheep.name,
|
||||
"icon": sheep.icon,
|
||||
"uuid": sheep.uuid,
|
||||
"appointment": sheep.appointment,
|
||||
"can_view_stand": sheep.can_view_stand == 0 ? false : true,
|
||||
"can_view_schedule": sheep.can_view_schedule == 0 ? false : true,
|
||||
"can_view_territory": sheep.can_view_territory == 0 ? false : true,
|
||||
"administrator": {
|
||||
"id": sheep.administrators_id ? sheep.administrators_id : false,
|
||||
"uuid": null
|
||||
},
|
||||
"moderator": {
|
||||
"id": sheep.moderators_id ? sheep.moderators_id : false,
|
||||
"uuid": null,
|
||||
"can_add_sheeps": sheep.can_add_sheeps == 1 ? true : false,
|
||||
"can_add_territory": sheep.can_add_territory == 1 ? true : false,
|
||||
"can_manager_territory": sheep.can_manager_territory == 1 ? true : false,
|
||||
"can_add_stand": sheep.can_add_stand == 1 ? true : false,
|
||||
"can_manager_stand": sheep.can_manager_stand == 1 ? true : false,
|
||||
"can_add_schedule": sheep.can_add_schedule == 1 ? true : false
|
||||
id: sheep.id,
|
||||
group_id: sheep.group_id,
|
||||
name: sheep.name,
|
||||
icon: sheep.icon,
|
||||
uuid: sheep.uuid,
|
||||
uuid_manager: mode && mode == 2 ? sheep.uuid_manager : null,
|
||||
appointment: sheep.appointment,
|
||||
mode: mode ? Number(sheep.mode) : 0,
|
||||
sheepRole: sheep.mode_title,
|
||||
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_schedule: sheep.can_view_schedule == 1 ? true : false,
|
||||
can_view_stand: sheep.can_view_stand == 1 ? true : false,
|
||||
can_view_territory: sheep.can_view_territory == 1 ? true : false
|
||||
}
|
||||
}
|
||||
|
||||
if (sheepRole == "administrator") {
|
||||
if (sheep.administrators_id) {
|
||||
data.administrator.uuid = sheep.administrators_uuid;
|
||||
}
|
||||
}
|
||||
if (sheepRole == "moderator") {
|
||||
if (sheep.moderators_id) {
|
||||
data.moderator.uuid = sheep.moderators_uuid;
|
||||
}
|
||||
if (mode && (mode == 1 || mode == 2)) {
|
||||
data.possibilities.can_add_sheeps = sheep.can_add_sheeps == 1 ? true : false;
|
||||
data.possibilities.can_view_sheeps = sheep.can_view_sheeps == 1 ? true : false;
|
||||
data.possibilities.can_add_territory = sheep.can_add_territory == 1 ? true : false;
|
||||
data.possibilities.can_manager_territory = sheep.can_manager_territory == 1 ? true : false;
|
||||
data.possibilities.can_add_stand = sheep.can_add_stand == 1 ? true : false;
|
||||
data.possibilities.can_manager_stand = sheep.can_manager_stand == 1 ? true : false;
|
||||
data.possibilities.can_add_schedule = sheep.can_add_schedule == 1 ? true : false;
|
||||
}
|
||||
|
||||
return res(data);
|
||||
|
||||
Reference in New Issue
Block a user