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("Отчёт по продажам", `