Додані повідомлення та перепрацьована структура застосунку та api

This commit is contained in:
2026-03-15 00:25:10 +02:00
parent 85483b85bb
commit 4bc9c11512
101 changed files with 5763 additions and 2546 deletions

View File

@@ -0,0 +1,91 @@
const HomesteadJointService = require('../services/homestead.joint.service');
class HomesteadJointController {
async getList(req, res) {
const { homestead_id } = req.params;
if (homestead_id) {
if (req.possibilities.can_joint_territory) {
let result = await HomesteadJointService.getList(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 createJoint(req, res) {
const { homestead_id } = req.params;
const data = req.body;
if (homestead_id) {
if (req.possibilities.can_joint_territory) {
let result = await HomesteadJointService.createJoint(
homestead_id,
data
);
if (result) {
return res.status(200).send(result);
} else {
return res.status(500).send({
message: 'Unable create joint homestead.',
});
}
} else {
return res
.status(404)
.send({ message: 'User not found.' });
}
} else {
return res
.status(404)
.send({ message: 'Users not found.' });
}
}
async deleteJoint(req, res) {
const { homestead_id } = req.params;
const data = req.body;
if (homestead_id) {
if (req.possibilities.can_joint_territory) {
let result = await HomesteadJointService.deleteJoint(
homestead_id,
data
);
if (result) {
return res.status(200).send(result);
} else {
return res.status(500).send({
message: 'Unable delete joint homestead.',
});
}
} else {
return res
.status(404)
.send({ message: 'User not found.' });
}
} else {
return res
.status(404)
.send({ message: 'Users not found.' });
}
}
}
module.exports = new HomesteadJointController();

View File

@@ -13,6 +13,8 @@ class HomesteadsController {
id = req.sheepId;
} else if (mode == "group") {
id = req.group_id;
} else if (mode == "joint") {
id = req.sheepId;
}
let result = await HomesteadsService.getList(mode, id);

View File

@@ -45,7 +45,7 @@ class SheepsController {
}
async getListStand(req, res) {
if (req.possibilities.can_view_stand) {
if (req.possibilities.can_view_stand) {
const result = await SheepsService.getListStand(req.mode);
if (result) {
@@ -86,7 +86,7 @@ class SheepsController {
const data = req.body;
if (req.mode == 2) {
let result = await SheepsService.updateSheep(data);
let result = await SheepsService.updateSheep(data, 2);
if (result) {
return res.status(200).send(result);
@@ -95,10 +95,24 @@ class SheepsController {
message: 'Unable update sheep.',
});
}
} if (req.possibilities.can_manager_sheeps) {
if (Number(data.mode) == 2) {
return res.status(403).send({ message: 'The sheep does not have enough rights.' });
} else {
let result = await SheepsService.updateSheep(data, 1);
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.' });
.send({ message: 'The sheep does not have enough rights.' });
}
}