Слияние части C этапа 2 (сертификаты, сверка, история, chargeback, fraud)

This commit is contained in:
2026-11-23 16:58:46 +03:00
32 changed files with 2620 additions and 38 deletions

View File

@@ -1,5 +1,6 @@
import Fastify, { type FastifyInstance } from "fastify";
import type { Pool } from "khb_common";
import { registerChargebackRoutes } from "./chargeback-http.js";
import { registerMcp } from "./mcp.js";
import type { AccountingSettings } from "./settings.js";
@@ -18,8 +19,17 @@ export interface JobHandlers {
"receipt-search": () => Promise<unknown>;
/** Раз в неделю: отчёт Анастасии о непринесённых чеках. */
"receipt-weekly-report": () => Promise<unknown>;
/** Этап 2 (необязательные: не настроенное задание отвечает 404). */
/** Страховые сертификаты: сроки, запросы подрядчикам, отметка «нет страховки» (раз в день). */
certificates?: () => Promise<unknown>;
/** Ежемесячная сверка выписок из Drive с QuickBooks. */
"reconcile-monthly"?: () => Promise<unknown>;
/** Еженедельный разбор истории правок -> отчёт Анастасии. */
"history-weekly"?: () => Promise<unknown>;
/** Еженедельное напоминание о незакрытых fraud по картам. */
"fraud-weekly"?: () => Promise<unknown>;
}
export const JOB_NAMES = ["invoices-mail", "finalize", "categorize", "summary", "fraud-flags", "invoice-check", "invoice-paid", "receipts-slack", "receipt-search", "receipt-weekly-report"] as const;
export const JOB_NAMES = ["invoices-mail", "finalize", "categorize", "summary", "fraud-flags", "invoice-check", "invoice-paid", "receipts-slack", "receipt-search", "receipt-weekly-report", "certificates", "reconcile-monthly", "history-weekly", "fraud-weekly"] as const;
export interface ApiDeps {
pool: Pool;
@@ -52,7 +62,7 @@ export function buildApi(deps: ApiDeps): FastifyInstance {
*/
app.post<{ Params: { name: string }; Querystring: { wait?: string } }>("/jobs/:name", async (req, reply) => {
const name = req.params.name as keyof JobHandlers;
const handler = Object.prototype.hasOwnProperty.call(deps.jobs, name) ? deps.jobs[name] : undefined;
const handler = Object.prototype.hasOwnProperty.call(deps.jobs, name) && (JOB_NAMES as readonly string[]).includes(name) ? deps.jobs[name] : undefined;
if (!handler) return reply.code(404).send({ error: "unknown_job" });
if (running.has(name)) return reply.code(409).send({ error: "already_running" });
running.add(name);
@@ -77,6 +87,9 @@ export function buildApi(deps: ApiDeps): FastifyInstance {
return reply.code(202).send({ job: name, started: true });
});
// --- ручки chargeback для ассистента менеджера (под токеном сервиса)
registerChargebackRoutes(app, { pool: deps.pool });
// --- MCP для Claude сотрудников (Streamable HTTP, без сессий)
if (deps.settings.mcp.enabled) {
const base = deps.settings.mcp.publicUrl?.replace(/\/$/, "");