peppa/bench/tasks/06-refactor/repo/product/routes.mjs
Асель d108197f0f PEP-184: задачи 5–8, тест набора, archive change, память
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 02:09:17 +05:00

29 lines
1.1 KiB
JavaScript

import { collection } from "./lib/store.mjs";
import { html, json, page } from "./lib/http.mjs";
import { buildReport, renderReport } from "./report.mjs";
const orders = collection("orders");
export const routes = [
{
method: "GET",
path: "/healthz",
handler: ({ res }) => {
res.writeHead(200, { "content-type": "text/plain; charset=utf-8" });
res.end("ok");
},
},
{ method: "GET", path: "/api/orders", handler: ({ res }) => json(res, 200, orders.all()) },
{
// Отчёт: /report?from=2026-11-01&to=2026-11-30&by=day|manager|city
method: "GET",
path: "/report",
handler: ({ res, query }) => {
const by = query.by || "day";
const report = buildReport(orders.all(), { from: query.from, to: query.to, groupBy: by });
html(res, page("Отчёт по продажам", `<h1>Отчёт по продажам</h1>${renderReport(report, by)}`));
},
},
{ method: "GET", path: "/", handler: ({ res }) => html(res, page("Продажи", '<h1>Продажи</h1><a href="/report">Отчёт</a>')) },
];