рабочее решение: сервер + data.json, полный процесс сверки, роль эксперта/руководителя, выгрузка списка

This commit is contained in:
tore 2026-09-22 17:29:14 +00:00
parent ed365a148a
commit b173f6865f
6 changed files with 665 additions and 400 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
node_modules/
data.json
.vibe42-run.log
.vibe42-run.pid

View File

@ -21,9 +21,9 @@
</div>
<nav id="snav" aria-label="Разделы" style="display:flex;flex-direction:column;gap:2px"></nav>
<div class="sb-bottom">
<button class="kt-ai-nav-item sb-util" id="sbUser">
<span class="kt-ai-avatar" style="width:20px;height:20px;font-size:8px;flex:0 0 20px" id="sbAvatar">АЖ</span>
<span class="nav-label" id="sbName">Айгуль Жумабекова</span>
<button class="kt-ai-nav-item sb-util" id="sbUser" title="Переключить роль">
<span class="kt-ai-avatar" style="width:20px;height:20px;font-size:8px;flex:0 0 20px" id="sbAvatar">ЭК</span>
<span class="nav-label" id="sbName">Эксперт</span>
</button>
</div>
</aside>

10
package-lock.json generated Normal file
View File

@ -0,0 +1,10 @@
{
"name": "sverka-dokumentov-pri-naznac",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sverka-dokumentov-pri-naznac"
}
}
}

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"name": "sverka-dokumentov-pri-naznac",
"private": true,
"type": "commonjs",
"scripts": { "start": "node server.js" }
}

944
script.js

File diff suppressed because it is too large Load Diff

95
server.js Normal file
View File

@ -0,0 +1,95 @@
const http = require("http");
const fs = require("fs");
const path = require("path");
const PORT = process.env.PORT || 3000;
const DATA = path.join(__dirname, "data.json");
function readData() {
try { return JSON.parse(fs.readFileSync(DATA, "utf8")); } catch (_) { return { items: [], log: [] }; }
}
function writeData(d) { fs.writeFileSync(DATA, JSON.stringify(d, null, 2)); }
function body(req) {
return new Promise((resolve) => {
let s = "";
req.on("data", (c) => (s += c));
req.on("end", () => { try { resolve(JSON.parse(s || "{}")); } catch (_) { resolve({}); } });
});
}
http.createServer(async (req, res) => {
const url = req.url.split("?")[0];
res.setHeader("Content-Type", "application/json; charset=utf-8");
// API: все карточки кандидата
if (req.method === "GET" && url === "/api/cards") {
const d = readData();
res.end(JSON.stringify(d.items || []));
return;
}
// API: получить одну карточку
if (req.method === "GET" && url.startsWith("/api/cards/")) {
const id = url.split("/").pop();
const d = readData();
const card = (d.items || []).find((x) => String(x.id) === String(id));
if (!card) { res.writeHead(404); res.end(JSON.stringify({ error: "not found" })); return; }
res.end(JSON.stringify(card));
return;
}
// API: создать новую карточку
if (req.method === "POST" && url === "/api/cards") {
const b = await body(req);
const d = readData();
const card = {
id: Date.now(),
name: b.name || "",
post: b.post || "",
submitted: new Date().toISOString().slice(0, 10),
stage: "uploaded",
files: [],
analysisStatus: "idle",
violations: [],
checks: {},
text: "",
sentAt: null,
returned: null,
approvedAt: null,
createdAt: new Date().toISOString()
};
d.items.push(card);
d.log = d.log || [];
d.log.push({ when: new Date().toISOString(), what: "Создана карточка «" + card.name + "»" });
writeData(d);
res.end(JSON.stringify(card));
return;
}
// API: обновить карточку
if (req.method === "PUT" && url.startsWith("/api/cards/")) {
const id = url.split("/").pop();
const b = await body(req);
const d = readData();
const idx = (d.items || []).findIndex((x) => String(x.id) === String(id));
if (idx === -1) { res.writeHead(404); res.end(JSON.stringify({ error: "not found" })); return; }
d.items[idx] = Object.assign(d.items[idx], b, { id });
d.log = d.log || [];
d.log.push({ when: new Date().toISOString(), what: "Обновлена карточка «" + d.items[idx].name + "»" });
writeData(d);
res.end(JSON.stringify(d.items[idx]));
return;
}
// Статика
let file = url === "/" ? "/index.html" : url;
const full = path.join(__dirname, file);
if (full.startsWith(__dirname) && fs.existsSync(full) && fs.statSync(full).isFile()) {
const ext = path.extname(full);
const type = ext === ".css" ? "text/css" : ext === ".js" ? "application/javascript" : "text/html";
res.writeHead(200, { "Content-Type": type + "; charset=utf-8" });
res.end(fs.readFileSync(full));
return;
}
res.writeHead(404); res.end("Not found");
}).listen(PORT, () => console.log("Сервер на порту " + PORT));