Додана сторінка "Розклад зібрань"

Перероблен генератор карточок територій APІ
This commit is contained in:
2025-11-22 20:17:50 +02:00
parent 04f39da611
commit 4b96ef0806
50 changed files with 1486 additions and 494 deletions

View File

@@ -1,204 +1,7 @@
const db = require("../config/db");
const saveCards = require("../middleware/genCards");
const genCards = require("../middleware/genCards");
class ConstructorService {
// createPack(data) {
// return new Promise((res, rej) => {
// let sql = `
// INSERT INTO
// house(
// group_id,
// title,
// number,
// points,
// points_number,
// geo,
// osm_id,
// settlement,
// created_at
// )
// VALUES
// (?, ?, ?, ?, ?, ?, ?, ?, ?)
// `;
// db.run(sql, [
// Number(data.house.group_id),
// data.house.title,
// data.house.number,
// JSON.stringify(data.house.points),
// JSON.stringify(data.house.points_number),
// JSON.stringify(data.house.geo),
// JSON.stringify(data.house.osm_id),
// data.house.settlement,
// Math.floor(Date.now())
// ], function (err) {
// if (err) {
// console.error(err.message);
// return res(false);
// } else if (this.changes === 0) {
// return res(false);
// } else {
// const houseId = this.lastID;
// const entranceStmt = db.prepare(`
// INSERT INTO
// entrance(
// house_id,
// entrance_number,
// title,
// points,
// points_number,
// created_at
// )
// VALUES
// (?, ?, ?, ?, ?, ?)`);
// const apartmentStmt = db.prepare(`
// INSERT INTO
// apartments(
// entrance_id,
// apartment_number,
// floors_number,
// updated_at
// )
// VALUES
// (?, ?, ?, ?)`);
// data.entrance.forEach((e, index) => {
// entranceStmt.run(
// houseId,
// Number(e.entrance_number),
// e.title,
// JSON.stringify(e.points),
// JSON.stringify(e.points_number),
// Math.floor(Date.now()),
// function (err) {
// if (err) {
// console.error(err.message);
// return;
// }
// const entranceId = this.lastID;
// if (data.apartments[e.editor_id]) {
// data.apartments[e.editor_id].forEach(apartment => {
// apartmentStmt.run(
// entranceId,
// apartment.apartment_number,
// apartment.floors_number,
// Math.floor(Date.now())
// );
// });
// }
// }
// );
// });
// entranceStmt.finalize();
// apartmentStmt.finalize();
// // res({ "status": "ok", "id": houseId });
// }
// });
// });
// }
// createPack(data) {
// return new Promise((res, rej) => {
// if (data.type == "house") {
// const sql = `
// INSERT INTO house (
// title, number, points, points_number, geo, osm_id, settlement, created_at
// ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`;
// db.run(sql, [
// data.title,
// data.number,
// JSON.stringify(data.points),
// JSON.stringify(data.points_number),
// JSON.stringify(data.geo),
// JSON.stringify(data.osm_id),
// data.settlement,
// Math.floor(Date.now())
// ], function (err) {
// if (err) {
// console.error(err.message);
// return res(false);
// }
// if (this.changes === 0) {
// return res(false);
// }
// const houseId = this.lastID;
// saveCards({ center: data.geo, wayId: data.osm_id, zoom: data.zoom ?? 18, type: "house", number: houseId, address: `${data.title} ${data.number}` });
// const entranceStmt = db.prepare(`
// INSERT INTO entrance (
// house_id, entrance_number, title, points, points_number, created_at
// ) VALUES (?, ?, ?, ?, ?, ?)`);
// const apartmentStmt = db.prepare(`
// INSERT INTO apartments (
// entrance_id, apartment_number, title, floors_number
// ) VALUES (?, ?, ?, ?)`);
// const entranceIdMap = {}; // Для сопоставления editor_id → entrance_id
// let pendingEntrances = data.entrance.length;
// data.entrance.forEach((e) => {
// entranceStmt.run(
// houseId,
// Number(e.entrance_number),
// e.title,
// JSON.stringify(e.points),
// JSON.stringify(e.points_number),
// Math.floor(Date.now()),
// function (err) {
// if (err) {
// console.error(err.message);
// return;
// }
// const entranceId = this.lastID;
// entranceIdMap[e.editor_id] = entranceId;
// if (--pendingEntrances === 0) {
// insertApartments();
// }
// }
// );
// });
// function insertApartments() {
// for (const [editor_id, apartments] of Object.entries(data.apartments)) {
// const entranceId = entranceIdMap[editor_id];
// if (!entranceId) continue;
// apartments.forEach(apartment => {
// apartmentStmt.run(
// entranceId,
// Number(apartment.apartment_number),
// apartment.title,
// apartment.floors_number
// );
// });
// }
// entranceStmt.finalize();
// apartmentStmt.finalize();
// res({ "status": "ok", "id": houseId });
// }
// });
// } else if (data.type == "homestead") {
// return res(false);
// } else {
// return res(false);
// }
// });
// }
createPack(data) {
return new Promise((res, rej) => {
@@ -228,8 +31,6 @@ class ConstructorService {
const houseId = this.lastID;
// saveCards({ center: data.geo, wayId: data.osm_id, zoom: data.zoom ?? 18, type: "house", number: houseId, address: `${data.title} ${data.number}` });
const entranceStmt = db.prepare(`
INSERT INTO entrance (
house_id, entrance_number, title, created_at
@@ -287,6 +88,8 @@ class ConstructorService {
);
});
genCards({type: "house", id: houseId});
function finalize() {
entranceStmt.finalize();
apartmentStmt.finalize();
@@ -321,8 +124,6 @@ class ConstructorService {
const homesteadId = this.lastID;
// saveCards({ center: data.geo, wayId: data.osm_id, zoom: data.zoom ?? 17, type: "homestead", number: homesteadId, address: `${data.title} ${data.number}` });
const buildingStmt = db.prepare(`
INSERT INTO buildings (
homestead_id, title, geo
@@ -351,6 +152,8 @@ class ConstructorService {
);
});
genCards({type: "homestead", id: homesteadId});
function finalize() {
buildingStmt.finalize();
res({ status: "ok", id: homesteadId });

View File

@@ -272,11 +272,11 @@ class StandService {
console.error(err.message);
return res(false);
}
// Notification.sendStand({
// title: "Додан новий день служіння",
// body: `Стенд «${stand.title}» поповнився, встигніть записатися.`,
// page: `/stand/card/${stand.id}`
// });
Notification.sendStand({
title: "Додан новий день служіння",
body: `Стенд «${stand.title}» поповнився, встигніть записатися.`,
page: `/stand/card/${stand.id}`
});
res({ status: "ok", inserted: list.length });
});