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();
|
||||
Reference in New Issue
Block a user