refactor(f4): align inspection wrapper with canonical contract
This commit is contained in:
@@ -8,16 +8,11 @@ import type { InspectionVisitView } from './inspection-visits.service';
|
||||
import { InspectionVisitsService } from './inspection-visits.service';
|
||||
|
||||
/**
|
||||
* Capa activa F4 sobre el servicio histórico de Inspecciones.
|
||||
* Capa activa F4 sobre el servicio de Inspecciones.
|
||||
*
|
||||
* Mantiene las operaciones de planificación/equipo/Inventario ya probadas, pero
|
||||
* elimina de la salida funcional los conceptos retirados en F4:
|
||||
* - no existe un título de negocio independiente del código institucional;
|
||||
* - no existe fecha prevista de fin;
|
||||
* - el checklist es exclusivamente técnico y nunca depende de respuestas de empresa.
|
||||
*
|
||||
* Las columnas legacy permanecen temporalmente en PostgreSQL para una migración de
|
||||
* limpieza posterior a la validación del piloto, sin intervenir datos históricos a ciegas.
|
||||
* Conserva las operaciones de planificación/equipo/Inventario ya probadas y aplica
|
||||
* la clasificación técnica F4 del checklist. El contrato público de Inspección ya
|
||||
* no expone título independiente ni fecha prevista de fin.
|
||||
*/
|
||||
@Injectable()
|
||||
export class F4InspectionVisitsService extends InspectionVisitsService {
|
||||
@@ -32,13 +27,13 @@ export class F4InspectionVisitsService extends InspectionVisitsService {
|
||||
const response = await super.list(query);
|
||||
return {
|
||||
...response,
|
||||
data: response.data.map((visit) => this.normalizeVisit(visit)),
|
||||
data: response.data.map((visit) => this.normalizeChecklist(visit)),
|
||||
};
|
||||
}
|
||||
|
||||
override async getById(id: string): Promise<InspectionVisitView> {
|
||||
await this.reclassifyCurrentChecklist(id);
|
||||
return this.normalizeVisit(await super.getById(id));
|
||||
return this.normalizeChecklist(await super.getById(id));
|
||||
}
|
||||
|
||||
override async create(
|
||||
@@ -48,7 +43,7 @@ export class F4InspectionVisitsService extends InspectionVisitsService {
|
||||
): Promise<InspectionVisitView> {
|
||||
const created = await super.create(dto, principal, request);
|
||||
await this.reclassifyCurrentChecklist(created.id);
|
||||
return this.normalizeVisit(await super.getById(created.id));
|
||||
return this.normalizeChecklist(await super.getById(created.id));
|
||||
}
|
||||
|
||||
override async generateChecklist(
|
||||
@@ -58,27 +53,18 @@ export class F4InspectionVisitsService extends InspectionVisitsService {
|
||||
): Promise<InspectionVisitView> {
|
||||
await super.generateChecklist(id, principal, request);
|
||||
await this.reclassifyCurrentChecklist(id);
|
||||
return this.normalizeVisit(await super.getById(id));
|
||||
return this.normalizeChecklist(await super.getById(id));
|
||||
}
|
||||
|
||||
private normalizeVisit<T extends { code: string; title: string; plannedEndAt: Date | null }>(visit: T): T {
|
||||
const normalized = {
|
||||
...visit,
|
||||
// Compatibilidad de contrato: consumidores antiguos reciben el identificador,
|
||||
// no un segundo nombre persistente que pueda divergir.
|
||||
title: visit.code,
|
||||
plannedEndAt: null,
|
||||
} as T;
|
||||
|
||||
if ('checklist' in normalized) {
|
||||
const view = normalized as T & InspectionVisitView;
|
||||
view.checklist = {
|
||||
...view.checklist,
|
||||
companyOverdue: 0,
|
||||
items: view.checklist.items.filter((item) => item.itemKind !== 'COMPANY_OVERDUE'),
|
||||
};
|
||||
}
|
||||
return normalized;
|
||||
private normalizeChecklist<T>(visit: T): T {
|
||||
if (!visit || typeof visit !== 'object' || !('checklist' in visit)) return visit;
|
||||
const view = visit as T & InspectionVisitView;
|
||||
view.checklist = {
|
||||
...view.checklist,
|
||||
companyOverdue: 0,
|
||||
items: view.checklist.items.filter((item) => item.itemKind !== 'COMPANY_OVERDUE'),
|
||||
};
|
||||
return view;
|
||||
}
|
||||
|
||||
private async reclassifyCurrentChecklist(visitId: string): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user