Додана сторінка "історія служіння"

This commit is contained in:
2025-09-20 20:02:46 +03:00
parent ff393417a1
commit d75fb7ec3d
23 changed files with 3065 additions and 1078 deletions

View File

@@ -0,0 +1,26 @@
const historyApartmentService = require('../services/history.apartment.service');
class historyApartmentController {
async getList(req, res) {
const { limit } = req.query;
if (req.mode == 2) {
let result = await historyApartmentService.getList(limit);
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.' });
}
}
}
module.exports = new historyApartmentController();

View File

@@ -0,0 +1,10 @@
const express = require('express');
const router = express.Router({ mergeParams: true });
const historyApartmentController = require('../controllers/history.apartment.controller');
const authenticate = require("../middleware/auth");
router
.route('/list')
.get(authenticate, historyApartmentController.getList);
module.exports = router;

View File

@@ -11,6 +11,7 @@ const entrancesRoutes = require('./entrances.routes');
const apartmentsRoutes = require('./apartments.routes');
const historyEntranceRoutes = require('./history.entrance.routes');
const historyHomesteadRoutes = require('./history.homestead.routes');
const historyApartmentRoutes = require('./history.apartment.routes');
const standRoutes = require('./stand.routes');
const pushRoutes = require('./push.routes');
@@ -27,6 +28,7 @@ router.use('/house/:house_id/entrances', entrancesRoutes);
router.use('/apartments?/:entrance_id', apartmentsRoutes);
router.use('/history/entrance/:entrance_id', historyEntranceRoutes);
router.use('/history/homestead/:homestead_id', historyHomesteadRoutes);
router.use('/history/apartments?', historyApartmentRoutes);
router.use('/stand', standRoutes);
router.use('/push', pushRoutes);

View File

@@ -69,7 +69,7 @@ class EntrancesService {
`;
db.run(sql, [
house_id,
Number(house_id),
Number(data.entrance_number),
data.title,
data.description,
@@ -101,10 +101,6 @@ class EntrancesService {
`;
db.run(sql, [
data.title,
JSON.stringify(data.points),
JSON.stringify(data.points_number),
data.floors_quantity,
data.apartments_quantity,
data.description,
Math.floor(new Date(Date.now()).getTime()),
data.id

View File

@@ -0,0 +1,69 @@
const db = require("../config/db");
class historyApartmentService {
getList(limit) {
return new Promise((res, rej) => {
let sql = `
SELECT
ah.*,
s.name AS sheep_name,
s.group_id AS sheep_group_id,
s.icon AS sheep_icon,
h.title AS house_title,
h.number AS house_number,
h.id AS house_id,
e.title AS entrance_title,
a.title AS apartment_title
FROM
apartments_history ah
LEFT JOIN
sheeps s ON s.id = ah.sheep_id
LEFT JOIN
apartments a ON a.id = ah.apartments_id
LEFT JOIN
entrance e ON e.id = a.entrance_id
LEFT JOIN
house h ON h.id = e.house_id
ORDER BY
ah.id DESC
LIMIT ${limit ?? 100};
`;
db.all(sql, (err, rows) => {
if (err) {
console.error(err.message);
return res(false);
} else {
let data = rows.map((row) => {
return {
"id": Number(row.id),
"apartments_id": Number(row.apartments_id),
"house_id": Number(row.house_id),
"address": {
"house": {
"title": row.house_title,
"number": row.house_number
},
"entrance": row.entrance_title,
"apartment": row.apartment_title
},
"status": Number(row.status),
"description": row.description,
"sheep": {
"id": Number(row.sheep_id),
"name": row.sheep_name,
"group_id": Number(row.sheep_group_id),
"icon": row.sheep_icon
},
"created_at": Number(row.created_at)
}
})
return res(data);
}
});
});
}
}
module.exports = new historyApartmentService();

View File

@@ -36,8 +36,6 @@ class HousesService {
},
"entrance_number": Number(row.entrance_number),
"title": row.title,
"points": JSON.parse(row.points),
"points_number": JSON.parse(row.points_number),
"floors_quantity": row.floors_quantity,
"apartments_quantity": row.apartments_quantity,
"description": row.description,