task-h.5.3
This commit is contained in:
@@ -7,6 +7,8 @@ import {
|
||||
REPORT_JSON_PATH,
|
||||
REPORT_MARKDOWN_PATH,
|
||||
buildAuditPayload,
|
||||
classifyTemplateField,
|
||||
computeFieldDiff,
|
||||
createSqlClient,
|
||||
extractTemplateFields,
|
||||
getEffectiveMappedKeys,
|
||||
@@ -22,6 +24,24 @@ async function main() {
|
||||
try {
|
||||
const payload = await buildAuditPayload(sql);
|
||||
const fields = extractTemplateFields(payload.templateSchema);
|
||||
const previousVersion =
|
||||
(
|
||||
await sql`
|
||||
select schema_json as "schemaJson", version
|
||||
from crm_document_template_versions
|
||||
where template_id = (
|
||||
select template_id
|
||||
from crm_document_template_versions
|
||||
where id = ${payload.templateVersionId}
|
||||
limit 1
|
||||
)
|
||||
and id <> ${payload.templateVersionId}
|
||||
and deleted_at is null
|
||||
order by created_at desc
|
||||
limit 1
|
||||
`
|
||||
)[0] ?? null;
|
||||
const previousFields = previousVersion ? extractTemplateFields(previousVersion.schemaJson) : [];
|
||||
const { mappings, columns } = await getMappingsForVersion(sql, payload.templateVersionId);
|
||||
const fieldNames = new Set(fields.map((field) => field.name).filter(Boolean));
|
||||
const placeholderTokens = [...new Set(fields.flatMap((field) => field.tokens))].sort();
|
||||
@@ -50,12 +70,19 @@ async function main() {
|
||||
)
|
||||
.map((mapping) => mapping.placeholderKey);
|
||||
const duplicateFields = getDuplicateFieldNames(fields);
|
||||
const unknownFields = getUnknownFieldNames(fields);
|
||||
const unknownFields = getUnknownFieldNames(fields, mappedKeys);
|
||||
const fieldDiff = computeFieldDiff(fields, previousFields);
|
||||
const classifications = fields.map((field) => ({
|
||||
name: field.name,
|
||||
classification: classifyTemplateField(field, mappedKeys)
|
||||
}));
|
||||
const topicRows = Object.keys(payload.topicInputs).filter((key) => key.startsWith('topic_')).length;
|
||||
const topicItemRows = Object.keys(payload.topicInputs).filter((key) =>
|
||||
key.startsWith('item_topic_')
|
||||
).length;
|
||||
const itemTableMapping = mappings.find((mapping) => mapping.placeholderKey === 'items_table') ?? null;
|
||||
const priceTableMapping =
|
||||
mappings.find((mapping) => mapping.placeholderKey === 'quotation_price_data') ?? null;
|
||||
const itemTableColumns = itemTableMapping
|
||||
? columns.filter((column) => column.mappingId === itemTableMapping.id)
|
||||
: [];
|
||||
@@ -98,8 +125,12 @@ async function main() {
|
||||
version: payload.templateVersion,
|
||||
versionId: payload.templateVersionId,
|
||||
fieldCount: fields.length,
|
||||
previousVersion: previousVersion?.version ?? null,
|
||||
deletedFields: fieldDiff.deletedFields,
|
||||
newFields: fieldDiff.newFields,
|
||||
duplicateFields,
|
||||
unknownFields
|
||||
unknownFields,
|
||||
classifications
|
||||
},
|
||||
metrics: {
|
||||
topicCount: payload.quotationMetrics.topicCount,
|
||||
@@ -113,6 +144,12 @@ async function main() {
|
||||
placeholderTokenCount: placeholderTokens.length,
|
||||
unmappedTokens,
|
||||
orphanMappings,
|
||||
priceTableMapping: priceTableMapping
|
||||
? {
|
||||
sourcePath: priceTableMapping.sourcePath,
|
||||
dataType: priceTableMapping.dataType
|
||||
}
|
||||
: null,
|
||||
itemTableColumns: itemTableColumns.map((column) => ({
|
||||
columnName: column.columnName,
|
||||
sourceField: column.sourceField
|
||||
@@ -120,7 +157,10 @@ async function main() {
|
||||
},
|
||||
runtimePayload: {
|
||||
templateInputKeys: Object.keys(payload.templateInput).length,
|
||||
topicInputKeys: Object.keys(payload.topicInputs).length
|
||||
topicInputKeys: Object.keys(payload.topicInputs).length,
|
||||
priceTableRows: Array.isArray(payload.templateInput.quotation_price_data)
|
||||
? payload.templateInput.quotation_price_data.length
|
||||
: 0
|
||||
},
|
||||
consistency: {
|
||||
status: consistencyStatus,
|
||||
@@ -141,6 +181,7 @@ async function main() {
|
||||
`- Overall Status: ${report.overallStatus}`,
|
||||
`- Quotation Code: ${report.quotationCode}`,
|
||||
`- Template: ${report.template.templateName} v${report.template.version}`,
|
||||
`- Previous Version: ${report.template.previousVersion ?? 'None'}`,
|
||||
'',
|
||||
'## Metrics',
|
||||
'',
|
||||
|
||||
Reference in New Issue
Block a user