v0.0.1
This commit is contained in:
112
api/controllers/apartments.controller.js
Normal file
112
api/controllers/apartments.controller.js
Normal file
@@ -0,0 +1,112 @@
|
||||
const ApartmentsService = require('../services/apartments.service');
|
||||
|
||||
class ApartmentsController {
|
||||
async getApartments(req, res) {
|
||||
const { entrance_id } = req.params;
|
||||
|
||||
if (entrance_id) {
|
||||
if (req.sheepRole == "administrator" || (req.sheepRole == "moderator" && req.moderator.can_manager_territory) || req.can_view_territory) {
|
||||
let result = await ApartmentsService.getApartments(entrance_id);
|
||||
if (result) {
|
||||
return res
|
||||
.status(200)
|
||||
.send(result);
|
||||
} else {
|
||||
return res
|
||||
.status(500)
|
||||
.send({ message: 'Internal server error.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(401)
|
||||
.send({ message: 'Entrance not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async createApartments(req, res) {
|
||||
const { entrance_id } = req.params;
|
||||
const data = req.body;
|
||||
|
||||
if (entrance_id && data) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_add_territory) {
|
||||
let result = await ApartmentsService.createApartments(
|
||||
entrance_id,
|
||||
data
|
||||
);
|
||||
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable create apartment.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(401)
|
||||
.send({ message: 'Entrance not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async updateApartments(req, res) {
|
||||
const data = req.body;
|
||||
|
||||
if (data) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_add_territory) {
|
||||
let result = await ApartmentsService.updateApartments(data);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable update history apartment.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(401)
|
||||
.send({ message: 'Data not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async deleteApartments(req, res) {
|
||||
const data = req.body;
|
||||
|
||||
if (data) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_add_territory) {
|
||||
let result = await ApartmentsService.deleteApartments(data);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable delete history apartment.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(401)
|
||||
.send({ message: 'Data not found.' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new ApartmentsController();
|
||||
22
api/controllers/auth.controller.js
Normal file
22
api/controllers/auth.controller.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const AuthService = require('../services/auth.service');
|
||||
|
||||
class AuthController {
|
||||
async login(req, res) {
|
||||
if (req.sheepId && req.sheepRole) {
|
||||
const result = await AuthService.findUserByID(req.sheepId, req.sheepRole);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(404).send({
|
||||
message: 'Sheep not found.'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The sheep does not have enough rights.' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new AuthController();
|
||||
31
api/controllers/constructor.controller.js
Normal file
31
api/controllers/constructor.controller.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const ConstructorService = require('../services/constructor.service');
|
||||
|
||||
class ConstructorController {
|
||||
async createPack(req, res) {
|
||||
const data = req.body;
|
||||
|
||||
if (data) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_add_territory) {
|
||||
let result = await ConstructorService.createPack(data);
|
||||
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable create pack.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(401)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new ConstructorController();
|
||||
112
api/controllers/entrances.controller.js
Normal file
112
api/controllers/entrances.controller.js
Normal file
@@ -0,0 +1,112 @@
|
||||
const EntrancesService = require('../services/entrances.service');
|
||||
|
||||
class EntrancesController {
|
||||
async getEntrances(req, res) {
|
||||
const { house_id } = req.params;
|
||||
|
||||
if (house_id) {
|
||||
if (req.sheepRole == "administrator" || (req.sheepRole == "moderator" && req.moderator.can_manager_territory) || req.can_view_territory) {
|
||||
let result = await EntrancesService.getEntrances(house_id);
|
||||
if (result) {
|
||||
return res
|
||||
.status(200)
|
||||
.send(result);
|
||||
} else {
|
||||
return res
|
||||
.status(500)
|
||||
.send({ message: 'Internal server error.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'House not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async createEntrance(req, res) {
|
||||
const { house_id } = req.params;
|
||||
const data = req.body;
|
||||
|
||||
if (house_id) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_add_territory) {
|
||||
let result = await EntrancesService.createEntrance(
|
||||
house_id,
|
||||
data
|
||||
);
|
||||
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable create entrance.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'House not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async updateEntrance(req, res) {
|
||||
const data = req.body;
|
||||
|
||||
if (data) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_add_territory) {
|
||||
let result = await EntrancesService.updateEntrance(data);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable update entrance.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Data not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async deleteEntrance(req, res) {
|
||||
const data = req.body;
|
||||
|
||||
if (data) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_add_territory) {
|
||||
let result = await EntrancesService.deleteEntrance(data);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable delete entrance.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Data not found.' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new EntrancesController();
|
||||
29
api/controllers/generator.cards.controller.js
Normal file
29
api/controllers/generator.cards.controller.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const saveCards = require("../middleware/genCards");
|
||||
|
||||
class GeneratorCardsController {
|
||||
async getScreen(req, res) {
|
||||
const { lat, lng, type, wayId, zoom, id, address, number } = req.query;
|
||||
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_add_territory) {
|
||||
let result = await saveCards({ center: {lat:lat,lng:lng}, wayId: wayId, zoom: zoom ?? 18, type: type, number: id, address: `${address} ${number}` });
|
||||
|
||||
console.log(result);
|
||||
|
||||
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Image creation error.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new GeneratorCardsController();
|
||||
112
api/controllers/history.entrance.controller.js
Normal file
112
api/controllers/history.entrance.controller.js
Normal file
@@ -0,0 +1,112 @@
|
||||
const HistoryEntranceService = require('../services/history.entrance.service');
|
||||
|
||||
class HistoryEntranceController {
|
||||
async getHistoryEntrance(req, res) {
|
||||
const { entrance_id } = req.params;
|
||||
|
||||
if (entrance_id) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_manager_territory) {
|
||||
let result = await HistoryEntranceService.getHistoryEntrance(entrance_id);
|
||||
if (result) {
|
||||
return res
|
||||
.status(200)
|
||||
.send(result);
|
||||
} else {
|
||||
return res
|
||||
.status(500)
|
||||
.send({ message: 'Internal server error.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async createHistoryEntrance(req, res) {
|
||||
const { entrance_id } = req.params;
|
||||
const data = req.body;
|
||||
|
||||
if (entrance_id) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_manager_territory) {
|
||||
let result = await HistoryEntranceService.createHistoryEntrance(
|
||||
entrance_id,
|
||||
data
|
||||
);
|
||||
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable create history entrance.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async updateHistoryEntrance(req, res) {
|
||||
const { entrance_id } = req.params;
|
||||
|
||||
if (entrance_id) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_manager_territory) {
|
||||
let result = await HistoryEntranceService.updateHistoryEntrance(entrance_id);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable update history entrance.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async deleteHistoryEntrance(req, res) {
|
||||
const { entrance_id } = req.params;
|
||||
|
||||
if (entrance_id) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_manager_territory) {
|
||||
let result = await HistoryEntranceService.deleteHistoryEntrance(entrance_id);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable delete history entrance.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new HistoryEntranceController();
|
||||
113
api/controllers/history.homestead.controller.js
Normal file
113
api/controllers/history.homestead.controller.js
Normal file
@@ -0,0 +1,113 @@
|
||||
const HistoryHomesteadService = require('../services/history.homestead.service');
|
||||
|
||||
class HistoryHomesteadController {
|
||||
async getHistoryHomestead(req, res) {
|
||||
const { homestead_id } = req.params;
|
||||
|
||||
if (homestead_id) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_manager_territory) {
|
||||
let result = await HistoryHomesteadService.getHistoryHomestead(homestead_id);
|
||||
if (result) {
|
||||
return res
|
||||
.status(200)
|
||||
.send(result);
|
||||
} else {
|
||||
return res
|
||||
.status(500)
|
||||
.send({ message: 'Internal server error.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async createHistoryHomestead(req, res) {
|
||||
const { homestead_id } = req.params;
|
||||
const data = req.body;
|
||||
|
||||
if (homestead_id) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_manager_territory) {
|
||||
let result = await HistoryHomesteadService.createHistoryHomestead(
|
||||
homestead_id,
|
||||
data
|
||||
);
|
||||
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable create history homestead.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async updateHistoryHomestead(req, res) {
|
||||
const { uuid } = req.query;
|
||||
const { homestead_id } = req.params;
|
||||
|
||||
if (homestead_id) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_manager_territory) {
|
||||
let result = await HistoryHomesteadService.updateHistoryHomestead(homestead_id);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable update history homestead.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async deleteHistoryHomestead(req, res) {
|
||||
const { homestead_id } = req.params;
|
||||
|
||||
if (homestead_id) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_manager_territory) {
|
||||
let result = await HistoryHomesteadService.deleteHistoryHomestead(homestead_id);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable delete history homestead.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new HistoryHomesteadController();
|
||||
143
api/controllers/homesteads.controller.js
Normal file
143
api/controllers/homesteads.controller.js
Normal file
@@ -0,0 +1,143 @@
|
||||
const HomesteadsService = require('../services/homesteads.service');
|
||||
|
||||
class HomesteadsController {
|
||||
async getList(req, res) {
|
||||
const { mode } = req.query;
|
||||
|
||||
if (req.sheepRole == "administrator" || (req.sheepRole == "moderator" && req.moderator.can_manager_territory) || req.can_view_territory) {
|
||||
let group_id = 0;
|
||||
let sheepName = false;
|
||||
|
||||
if (req.sheepRole == "administrator") {
|
||||
group_id = 0;
|
||||
} else if (req.sheepRole == "moderator") {
|
||||
group_id = req.group_id;
|
||||
}
|
||||
|
||||
if (mode == "sheep") {
|
||||
group_id = req.group_id;
|
||||
sheepName = req.sheepName;
|
||||
}
|
||||
|
||||
let result = await HomesteadsService.getList(group_id, sheepName);
|
||||
if (result) {
|
||||
return res
|
||||
.status(200)
|
||||
.send(result);
|
||||
} else {
|
||||
return res
|
||||
.status(500)
|
||||
.send({ message: 'Internal server error.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
}
|
||||
|
||||
async getHomestead(req, res) {
|
||||
const { homestead_id } = req.params;
|
||||
|
||||
if (homestead_id) {
|
||||
if (req.sheepRole == "administrator" || (req.sheepRole == "moderator" && req.moderator.can_manager_territory) || req.can_view_territory) {
|
||||
let result = await HomesteadsService.getHomestead(homestead_id);
|
||||
if (result) {
|
||||
return res
|
||||
.status(200)
|
||||
.send(result);
|
||||
} else {
|
||||
return res
|
||||
.status(500)
|
||||
.send({ message: 'Internal server error.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async createHomestead(req, res) {
|
||||
const data = req.body;
|
||||
|
||||
if (data) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_add_territory) {
|
||||
let result = await HomesteadsService.createHomestead(data);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable create homestead.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async updateHomestead(req, res) {
|
||||
const { homestead_id } = req.params;
|
||||
const data = req.body;
|
||||
|
||||
if (homestead_id) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_manager_territory) {
|
||||
let result = await HomesteadsService.updateHomestead(homestead_id, data);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable update homestead.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async deleteHomestead(req, res) {
|
||||
const { homestead_id } = req.params;
|
||||
|
||||
if (homestead_id) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_add_territory) {
|
||||
let result = await HomesteadsService.deleteHomestead(homestead_id);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable delete homestead.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new HomesteadsController();
|
||||
137
api/controllers/houses.controller.js
Normal file
137
api/controllers/houses.controller.js
Normal file
@@ -0,0 +1,137 @@
|
||||
const HousesService = require('../services/houses.service');
|
||||
|
||||
class HousesController {
|
||||
async getList(req, res) {
|
||||
const { mode } = req.query;
|
||||
|
||||
if (req.sheepRole == "administrator" || (req.sheepRole == "moderator" && req.moderator.can_manager_territory) || req.can_view_territory) {
|
||||
let group_id = 0;
|
||||
let sheepName = false;
|
||||
|
||||
if (req.sheepRole == "administrator") {
|
||||
group_id = 0;
|
||||
} else if (req.sheepRole == "moderator") {
|
||||
group_id = req.group_id;
|
||||
}
|
||||
|
||||
if (mode == "sheep") {
|
||||
group_id = req.group_id;
|
||||
sheepName = req.sheepName;
|
||||
}
|
||||
|
||||
let result = await HousesService.getList(group_id, sheepName);
|
||||
if (result) {
|
||||
return res
|
||||
.status(200)
|
||||
.send(result);
|
||||
} else {
|
||||
return res
|
||||
.status(500)
|
||||
.send({ message: 'Internal server error.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
}
|
||||
|
||||
async getHouse(req, res) {
|
||||
const { house_id } = req.params;
|
||||
|
||||
if (house_id) {
|
||||
if (req.sheepRole == "administrator" || (req.sheepRole == "moderator" && req.moderator.can_manager_territory) || req.can_view_territory) {
|
||||
let result = await HousesService.getHouse(house_id);
|
||||
if (result) {
|
||||
return res
|
||||
.status(200)
|
||||
.send(result);
|
||||
} else {
|
||||
return res
|
||||
.status(500)
|
||||
.send({ message: 'Internal server error.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async createHouse(req, res) {
|
||||
const data = req.body;
|
||||
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_add_territory) {
|
||||
let result = await HousesService.createHouse(data);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable create house.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async updateHouse(req, res) {
|
||||
const { house_id } = req.params;
|
||||
const data = req.body;
|
||||
|
||||
if (house_id) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_manager_territory) {
|
||||
let result = await HousesService.updateHouse(house_id, data);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable update house.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async deleteHouse(req, res) {
|
||||
const { house_id } = req.params;
|
||||
|
||||
if (house_id) {
|
||||
if (req.sheepRole == "administrator" || req.moderator.can_add_territory) {
|
||||
let result = await HousesService.deleteHouse(house_id);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable delete house.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new HousesController();
|
||||
24
api/controllers/rotation.controller.js
Normal file
24
api/controllers/rotation.controller.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const RotationService = require('../services/rotation.service');
|
||||
|
||||
class RotationController {
|
||||
async editTables(req, res) {
|
||||
if (req.sheepRole == "administrator") {
|
||||
let result = await RotationService.editTables();
|
||||
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The user does not have enough rights.' });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new RotationController();
|
||||
110
api/controllers/sheeps.controller.js
Normal file
110
api/controllers/sheeps.controller.js
Normal file
@@ -0,0 +1,110 @@
|
||||
const SheepsService = require('../services/sheeps.service');
|
||||
|
||||
class SheepsController {
|
||||
async getSheep(req, res) {
|
||||
const { uuid } = req.query;
|
||||
|
||||
if (uuid) {
|
||||
if (req.sheepRole) {
|
||||
const result = await SheepsService.getSheep(uuid, req.sheepRole);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(404).send({
|
||||
message: 'Sheep not found.'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The sheep does not have enough rights.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(401)
|
||||
.send({ message: 'Sheeps not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async getList(req, res) {
|
||||
if (req.sheepRole) {
|
||||
const result = await SheepsService.getList(req.sheepRole);
|
||||
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'User not found.' });
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(404)
|
||||
.send({ message: 'Users not found.' });
|
||||
}
|
||||
}
|
||||
|
||||
async createSheep(req, res) {
|
||||
const data = req.body;
|
||||
|
||||
if (req.sheepRole && (req.sheepRole == "administrator" || req.moderator.can_add_sheeps)) {
|
||||
let result = await SheepsService.createSheep(data);
|
||||
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable create sheep.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'The sheep does not have enough rights.' });
|
||||
}
|
||||
}
|
||||
|
||||
async updateSheep(req, res) {
|
||||
const { uuid } = req.query;
|
||||
const data = req.body;
|
||||
console.log("data", data);
|
||||
|
||||
|
||||
if (req.sheepRole == "administrator") {
|
||||
let result = await SheepsService.updateSheep(data);
|
||||
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable update sheep.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'Sheep not foundThe sheep does not have enough rights.' });
|
||||
}
|
||||
}
|
||||
|
||||
async deleteSheep(req, res) {
|
||||
const data = req.body;
|
||||
|
||||
if (req.sheepRole == "administrator") {
|
||||
let result = await SheepsService.deleteSheep(data);
|
||||
if (result) {
|
||||
return res.status(200).send(result);
|
||||
} else {
|
||||
return res.status(500).send({
|
||||
message: 'Unable delete sheep.',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.send({ message: 'Sheep not foundThe sheep does not have enough rights.' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new SheepsController();
|
||||
Reference in New Issue
Block a user