Очередь разбора: сумма/получатель/дата/адрес проекта, дата получения и дни; автоудаление уже проведённого; справочник проектов QuickBooks и закрытые проекты; запрос почты с Delivered-To (по встрече 2026-11-27)
All checks were successful
ci / test (push) Successful in 49s
ci / deploy (push) Successful in 2m58s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 18:01:37 +03:00
parent e716c82075
commit 24fed3d5a1
10 changed files with 200 additions and 20 deletions

View File

@@ -207,16 +207,70 @@ export class ReviewTools {
limit $5`,
[roles, (a.kind as string | undefined) ?? null, a.include_snoozed === true, this.now(), limit],
);
const lookups = await this.lookups(rows);
return {
total: rows[0]?.total ?? 0,
shown: rows.length,
tasks: rows.map((r) => {
const row = r.row as Json | null;
return { ...taskOut(r as Task), review: row, ...((r.kind === "invoice" || r.kind === "invoice_approval") && row ? { file_url: driveUrl(row.drive_file_id) } : {}) };
return {
...taskOut(r as Task),
review: row,
lookup: lookups.get(String(r.id)),
...((r.kind === "invoice" || r.kind === "invoice_approval") && row ? { file_url: driveUrl(row.drive_file_id) } : {}),
};
}),
};
}
/**
* Данные для читаемой таблицы: операция ленты (сумма, получатель, дата), адрес проекта и клиент вместо номера, название счёта.
* Проекты берутся из зеркала QuickBooks (Projects: адрес + клиент); закрытые отмечены в acc_project_closed.
*/
private async lookups(rows: { id: unknown; kind: unknown; ref_id: unknown; row: unknown }[]): Promise<Map<string, Json>> {
const out = new Map<string, Json>();
const feedIds = rows.filter((r) => r.kind === "categorization").map((r) => String(r.ref_id));
const feed = new Map<string, Json>();
if (feedIds.length) {
const f = await this.d.pool.query("select feed_txn_id, txn_date, amount, vendor_name, description from acc_feed_txn where feed_txn_id = any($1)", [feedIds]);
for (const x of f.rows) feed.set(String(x.feed_txn_id), x as Json);
}
const sugg = (r: { row: unknown }): Json => ((r.row as Json | null)?.suggestion ?? {}) as Json;
const projectOf = (r: { kind: unknown; row: unknown }): string | null => {
const v = r.kind === "categorization" ? sugg(r).project_customer_id : (r.row as Json | null)?.project_customer_id;
return v === null || v === undefined || v === "" ? null : String(v);
};
const projectIds = [...new Set(rows.map(projectOf).filter((x): x is string => !!x))];
const accountIds = [...new Set(rows.filter((r) => r.kind === "categorization").map((r) => sugg(r).account).filter((x) => x !== null && x !== undefined && x !== "").map(String))];
const projects = new Map<string, string>();
if (projectIds.length) {
const p = await this.d.pool.query(
`select c.id, c.display_name, par.display_name as client, (pc.customer_id is not null or not c.active) as closed
from qbo_customer c
left join qbo_customer par on par.realm_id = c.realm_id and par.id = c.parent_id
left join acc_project_closed pc on pc.customer_id = c.id
where c.id = any($1)`,
[projectIds],
);
for (const x of p.rows) projects.set(String(x.id), `${String(x.display_name)}${x.client ? ` (клиент ${String(x.client)})` : ""}${x.closed ? " [проект закрыт]" : ""}`);
}
const accounts = new Map<string, string>();
if (accountIds.length) {
const a = await this.d.pool.query("select id, coalesce(fully_qualified_name, name) as n from qbo_account where id = any($1)", [accountIds]);
for (const x of a.rows) accounts.set(String(x.id), String(x.n));
}
for (const r of rows) {
const pid = projectOf(r);
const acc = r.kind === "categorization" ? sugg(r).account : null;
out.set(String(r.id), {
feed: r.kind === "categorization" ? (feed.get(String(r.ref_id)) ?? null) : null,
project: pid ? (projects.get(pid) ?? null) : null,
account: acc ? (accounts.get(String(acc)) ?? null) : null,
});
}
return out;
}
/** acc_review_get */
async get(personId: string, a: Json): Promise<Json> {
const roles = this.rolesOf(personId);