v0.0.1
This commit is contained in:
84
api/services/auth.service.js
Normal file
84
api/services/auth.service.js
Normal file
@@ -0,0 +1,84 @@
|
||||
const db = require("../config/db");
|
||||
|
||||
class AuthService {
|
||||
findUserByID(id, sheepRole) {
|
||||
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;
|
||||
`
|
||||
db.get(sql, [id], (err, sheep) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return res(false);
|
||||
} else if (!sheep) {
|
||||
console.log({ "error": "uuid not found" });
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return res(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new AuthService();
|
||||
Reference in New Issue
Block a user