文件
hyb-oa/server/src/services/invoiceDocumentMeta.js
T
wangsli 8a9279efce
ci-e2e / e2e (push) Canceled after 0s
ci-minimal / check-minimal (push) Canceled after 0s
实现报销材料连续预览(07-27-yang-jun-reimbursement-readiness)
2026-08-01 00:17:54 +08:00

23 行
698 B
JavaScript

const SAFE_DOCUMENT_CATEGORIES = new Set([
"vat_invoice",
"full_vat_invoice",
"electronic_train_ticket",
]);
function normalizeSafeMetaString(value, maxLength = 64) {
if (typeof value !== "string") return null;
const normalized = value.trim();
return normalized ? normalized.slice(0, maxLength) : null;
}
function mapInvoiceDocumentMeta(invoice) {
const result = invoice?.ocr_result?.result_json;
const category = normalizeSafeMetaString(result?.documentCategory);
return {
documentCategory: SAFE_DOCUMENT_CATEGORIES.has(category) ? category : null,
documentSubtype: normalizeSafeMetaString(result?.documentSubtype),
};
}
module.exports = { mapInvoiceDocumentMeta };