fix(actas): keep sealed act content findings-only
This commit is contained in:
@@ -264,7 +264,6 @@ export class CompanySignatureInviteService {
|
||||
const invite = await this.resolveToken(this.dataSource.manager, token, false);
|
||||
const locked = invite.lockedSnapshot ?? {};
|
||||
const act = this.record(locked.act);
|
||||
const inventories = this.records(locked.inventories);
|
||||
const findings = this.records(locked.findings).map((finding) => ({
|
||||
id: finding.id,
|
||||
code: finding.code,
|
||||
@@ -296,12 +295,6 @@ export class CompanySignatureInviteService {
|
||||
documentNumber: invite.recipientDocumentNumber,
|
||||
position: invite.recipientPosition,
|
||||
},
|
||||
inventories: inventories.map((inventory) => ({
|
||||
id: inventory.id,
|
||||
code: inventory.code,
|
||||
name: inventory.name,
|
||||
typeName: inventory.typeName ?? inventory.typeCode ?? null,
|
||||
})),
|
||||
findings,
|
||||
consent: REMOTE_COMPANY_CONSENT,
|
||||
allowedActions: ['SIGN_CONFORMITY', 'SIGN_DISSENT', 'REFUSE'],
|
||||
|
||||
@@ -929,6 +929,12 @@ export class InspectionClosingService {
|
||||
JOIN assets asset ON asset.id=link.asset_id
|
||||
JOIN asset_types type ON type.id=asset.asset_type_id
|
||||
WHERE link.act_id=$1 AND link.included=true
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM inspection_findings finding
|
||||
WHERE finding.act_id=link.act_id
|
||||
AND finding.asset_id=asset.id
|
||||
AND finding.status<>'VOIDED'
|
||||
)
|
||||
ORDER BY asset.code,asset.id
|
||||
`, [actId]) as Array<Record<string, unknown>>;
|
||||
const findings = await manager.query(`
|
||||
|
||||
@@ -38,7 +38,6 @@ export async function buildInspectionActPdf(snapshot: Record<string, unknown>, i
|
||||
const act = asRecord(locked.act);
|
||||
const inspection = asRecord(act.inspection ?? act.visit);
|
||||
const responsible = asRecord(locked.responsible);
|
||||
const inventories = asArray(locked.inventories ?? locked.assets);
|
||||
const findings = asArray(locked.findings);
|
||||
const signatures = asArray(sealed.signatures);
|
||||
const hash = text(sealed.finalSha256 ?? sealed.lockedSha256);
|
||||
@@ -87,32 +86,19 @@ export async function buildInspectionActPdf(snapshot: Record<string, unknown>, i
|
||||
if (text(act.summary) && !isPlaceholder(act.summary)) body(act.summary);
|
||||
else body(`Se realizó la inspección ${text(inspection.code)}. El contenido constatado se detalla en los hallazgos registrados a continuación.`);
|
||||
if (act.observations) { label('Observaciones', act.observations); }
|
||||
if (inventories.length) {
|
||||
heading('Instalaciones inspeccionadas');
|
||||
for (const item of inventories) body(`${text(item.name)} (${text(item.code)}) · ${text(item.typeName ?? item.typeCode)}`);
|
||||
}
|
||||
heading('Hallazgos y fotografías');
|
||||
if (!findings.length) body('No se registraron hallazgos.');
|
||||
const shownAssetPhotos = new Set<string>();
|
||||
for (const finding of findings) {
|
||||
need(75);
|
||||
doc.font('body-bold').fillColor(blue).fontSize(11).text(`${text(finding.code)} · ${text(finding.title)}`);
|
||||
label('Descripción', finding.description);
|
||||
if (finding.legalBasis) label('Normativa consignada', finding.legalBasis);
|
||||
if (finding.severity != null) label('Gravedad', `${text(finding.severity)}/10`);
|
||||
for (const photo of images.filter((item) => item.findingId === text(finding.id))) image(photo, `Fotografía del hallazgo ${text(finding.code)}${photo.capturedAt ? ` · ${date(photo.capturedAt)}` : ''}`);
|
||||
for (const photo of images.filter((item) => item.assetId === text(finding.assetId))) {
|
||||
if (shownAssetPhotos.has(photo.id)) continue;
|
||||
shownAssetPhotos.add(photo.id);
|
||||
image(photo, `Fotografía de inventario ${text(photo.title)}${photo.capturedAt ? ` · ${date(photo.capturedAt)}` : ''}`);
|
||||
for (const photo of images.filter((item) => item.findingId === text(finding.id))) {
|
||||
image(photo, `Fotografía del hallazgo ${text(finding.code)}${photo.capturedAt ? ` · ${date(photo.capturedAt)}` : ''}`);
|
||||
}
|
||||
doc.moveDown(0.4);
|
||||
}
|
||||
const otherAssetPhotos = images.filter((item) => item.assetId && !shownAssetPhotos.has(item.id));
|
||||
if (otherAssetPhotos.length) {
|
||||
heading('Otras instalaciones inspeccionadas');
|
||||
for (const photo of otherAssetPhotos) image(photo, `Fotografía de inventario ${text(photo.title)}${photo.capturedAt ? ` · ${date(photo.capturedAt)}` : ''}`);
|
||||
}
|
||||
heading('Intervinientes y firmas');
|
||||
for (const signature of signatures) {
|
||||
const name = text(signature.signerName);
|
||||
|
||||
@@ -66,7 +66,7 @@ export class InspectionActPdfService {
|
||||
`, [actId]);
|
||||
try {
|
||||
const snapshot = { ...row.finalSnapshot, finalSha256: row.closureSha256 };
|
||||
const built = await buildInspectionActPdf(snapshot, await this.fieldImages(actId), await this.actContext(actId));
|
||||
const built = await buildInspectionActPdf(snapshot, await this.fieldImages(actId, false), await this.actContext(actId));
|
||||
await mkdir(this.root, { recursive: true, mode: 0o700 });
|
||||
const storedName = `${actId}.pdf`;
|
||||
const originalName = `${row.code}.pdf`;
|
||||
@@ -113,7 +113,7 @@ export class InspectionActPdfService {
|
||||
message: 'El Acta debe estar firmada y sellada para generar el documento consolidado',
|
||||
});
|
||||
const snapshot = { ...row.finalSnapshot, finalSha256: row.closureSha256 };
|
||||
const built = await buildInspectionActPdf(snapshot, await this.fieldImages(actId), await this.actContext(actId));
|
||||
const built = await buildInspectionActPdf(snapshot, await this.fieldImages(actId, false), await this.actContext(actId));
|
||||
await mkdir(this.root, { recursive: true, mode: 0o700 });
|
||||
const storedName = `${actId}-consolidado-${built.sha256.slice(0, 24)}.pdf`;
|
||||
const originalName = `${row.code}-consolidada.pdf`;
|
||||
@@ -176,7 +176,7 @@ export class InspectionActPdfService {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
async fieldImages(actId: string): Promise<ActPdfImage[]> {
|
||||
async fieldImages(actId: string, includeAssetPhotos = true): Promise<ActPdfImage[]> {
|
||||
type ImageRow = { id: string; findingId?: string; assetId?: string; signerName?: string; title?: string; capturedAt?: Date; storedName: string; sha256: string; sizeBytes: number };
|
||||
const findings = await this.dataSource.query(`
|
||||
SELECT evidence.id, finding.id AS "findingId", evidence.title,
|
||||
@@ -189,7 +189,7 @@ export class InspectionActPdfService {
|
||||
AND evidence.created_at<=act.locked_at
|
||||
ORDER BY finding.finding_number,evidence.captured_at,evidence.id
|
||||
`, [actId]) as ImageRow[];
|
||||
const assets = await this.dataSource.query(`
|
||||
const assets = includeAssetPhotos ? await this.dataSource.query(`
|
||||
SELECT media.id,asset.id AS "assetId", asset.name AS title,
|
||||
capture.device_captured_at AS "capturedAt",media.stored_name AS "storedName",
|
||||
media.sha256,media.size_bytes AS "sizeBytes"
|
||||
@@ -201,7 +201,7 @@ export class InspectionActPdfService {
|
||||
JOIN asset_media media ON media.id=capture.media_id AND media.deleted_at IS NULL AND media.kind='PHOTO'
|
||||
WHERE act.id=$1 AND capture.created_at<=act.locked_at
|
||||
ORDER BY capture.device_captured_at,media.id
|
||||
`, [actId]) as ImageRow[];
|
||||
`, [actId]) as ImageRow[] : [];
|
||||
const signatures = await this.dataSource.query(`
|
||||
SELECT signature.id,signature.signer_name AS "signerName",signature.stored_name AS "storedName",
|
||||
signature.image_sha256 AS sha256,signature.size_bytes AS "sizeBytes"
|
||||
|
||||
Reference in New Issue
Block a user