Додані повідомлення та перепрацьована структура застосунку та 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

@@ -1,4 +1,5 @@
const db = require("../config/db");
const genCards = require("../middleware/genCards");
class HomesteadsService {
getList(mode, id) {
@@ -63,6 +64,27 @@ class HomesteadsService {
AND
homestead_history.sheep_id = '${id}';
`;
} else if (mode == "joint") {
sql = `
SELECT
homestead.*,
homestead_history.id AS homestead_history_id,
homestead_history.name AS homestead_history_name,
homestead_history.group_id AS homestead_history_group_id,
homestead_history.sheep_id AS homestead_history_sheep_id,
homestead_history.date_start AS homestead_history_date_start,
homestead_history.date_end AS homestead_history_date_end
FROM
homestead
JOIN
homestead_history ON homestead.id = homestead_history.homestead_id
JOIN
homestead_joint ON homestead.id = homestead_joint.homestead_id
WHERE
homestead_joint.sheep_id = '${id}'
ORDER BY
homestead_history.date_start DESC;
`;
}
db.all(sql, (err, rows) => {
@@ -88,7 +110,7 @@ class HomesteadsService {
"id": row.homestead_history_id ? Number(row.homestead_history_id) : null,
"name": row.homestead_history_name,
"group_id": row.homestead_history_group_id ? Number(row.homestead_history_group_id) : null,
"sheep_id": row.entrance_history_sheep_id ? Number(row.entrance_history_sheep_id) : null,
"sheep_id": row.homestead_history_sheep_id ? Number(row.homestead_history_sheep_id) : null,
"date": {
"start": row.homestead_history_date_start ? Number(row.homestead_history_date_start) : null,
"end": row.homestead_history_date_end ? Number(row.homestead_history_date_end) : null
@@ -111,6 +133,7 @@ class HomesteadsService {
COALESCE((SELECT homestead_history.working FROM homestead_history WHERE homestead_history.homestead_id = homestead.id ORDER BY homestead_history.date_start DESC LIMIT 1), 0) AS working,
(SELECT homestead_history.name FROM homestead_history WHERE homestead_history.homestead_id = homestead.id ORDER BY homestead_history.date_start DESC LIMIT 1) AS homestead_history_name,
(SELECT homestead_history.group_id FROM homestead_history WHERE homestead_history.homestead_id = homestead.id ORDER BY homestead_history.date_start DESC LIMIT 1) AS homestead_history_group_id,
(SELECT homestead_history.sheep_id FROM homestead_history WHERE homestead_history.homestead_id = homestead.id ORDER BY homestead_history.date_start DESC LIMIT 1) AS homestead_history_sheep_id,
(SELECT homestead_history.id FROM homestead_history WHERE homestead_history.homestead_id = homestead.id ORDER BY homestead_history.date_start DESC LIMIT 1) AS homestead_history_id,
(SELECT homestead_history.date_start FROM homestead_history WHERE homestead_history.homestead_id = homestead.id ORDER BY homestead_history.date_start DESC LIMIT 1) AS homestead_history_date_start,
(SELECT homestead_history.date_end FROM homestead_history WHERE homestead_history.homestead_id = homestead.id ORDER BY homestead_history.date_start DESC LIMIT 1) AS homestead_history_date_end
@@ -144,6 +167,7 @@ class HomesteadsService {
"id": row.homestead_history_id ? Number(row.homestead_history_id) : null,
"name": row.homestead_history_name,
"group_id": row.homestead_history_group_id ? Number(row.homestead_history_group_id) : null,
"sheep_id": row.homestead_history_sheep_id ? Number(row.homestead_history_sheep_id) : null,
"date": {
"start": row.homestead_history_date_start ? Number(row.homestead_history_date_start) : null,
"end": row.homestead_history_date_end ? Number(row.homestead_history_date_end) : null
@@ -192,6 +216,7 @@ class HomesteadsService {
return res(false);
} else {
res({ "status": "ok", "id": this.lastID });
genCards({type: "homestead", id: this.lastID});
}
});
});
@@ -234,6 +259,7 @@ class HomesteadsService {
return res(false);
} else {
res({ "status": "ok", "id": homestead_id });
genCards({type: "homestead", id: homestead_id});
}
});
});