Ассистент бухгалтерии: чат accounting, промт, команда khb-acc, маршрут /acc (миграция 072, п.88)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { registerAgentRoutes } from "./agents-api.js";
|
||||
import { usageSummary, type UsageLog } from "./usage.js";
|
||||
import type { PrepJob, PrepResult } from "./jobs.js";
|
||||
import { checkMailAuth } from "./mail/auth.js";
|
||||
import { checkAccAuth, forwardAcc } from "./acc/proxy.js";
|
||||
import { checkChargebackAuth, forwardChargeback, type ChargebackConfig } from "./chargeback/proxy.js";
|
||||
import { resolveForManager, sendForManager, type MailDeps } from "./mail/service.js";
|
||||
|
||||
@@ -48,6 +49,10 @@ export function buildApi(deps: PrepApiDeps): FastifyInstance {
|
||||
if (!deps.mail || !checkMailAuth(deps.mail.secret, String(req.headers["x-khb-caller"] ?? ""), req.headers.authorization)) return reply.code(401).send({ error: "unauthorized" });
|
||||
return;
|
||||
}
|
||||
if (req.url.startsWith("/acc/")) {
|
||||
if (!deps.chargeback || !checkAccAuth(deps.chargeback.secret, String(req.headers["x-khb-caller"] ?? ""), req.headers.authorization)) return reply.code(401).send({ error: "unauthorized" });
|
||||
return;
|
||||
}
|
||||
if (req.url.startsWith("/chargeback/")) {
|
||||
if (!deps.chargeback || !checkChargebackAuth(deps.chargeback.secret, String(req.headers["x-khb-caller"] ?? ""), req.headers.authorization)) return reply.code(401).send({ error: "unauthorized" });
|
||||
return;
|
||||
@@ -75,6 +80,18 @@ export function buildApi(deps: PrepApiDeps): FastifyInstance {
|
||||
});
|
||||
}
|
||||
|
||||
if (deps.chargeback) {
|
||||
const cb = deps.chargeback;
|
||||
// ассистент бухгалтерии (команда khb-acc): токен собеседника; суммы и очередь - только ролям cfo и accountant
|
||||
app.post<{ Params: { action: string }; Body: Record<string, unknown> }>("/acc/:action", async (req, reply) => {
|
||||
const caller = String(req.headers["x-khb-caller"]);
|
||||
const body = req.body && typeof req.body === "object" && !Array.isArray(req.body) ? req.body : {};
|
||||
const row = (await deps.pool.query("select role_code from person where id = $1 and is_active", [caller])).rows[0] as { role_code: string | null } | undefined;
|
||||
const r = await forwardAcc(cb, req.params.action, caller, row?.role_code === "cfo" || row?.role_code === "accountant", body);
|
||||
return reply.code(r.status).send(r.body);
|
||||
});
|
||||
}
|
||||
|
||||
app.get("/healthz", async () => {
|
||||
let db = false;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user