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';
|
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
|
* Conserva las operaciones de planificación/equipo/Inventario ya probadas y aplica
|
||||||
* elimina de la salida funcional los conceptos retirados en F4:
|
* la clasificación técnica F4 del checklist. El contrato público de Inspección ya
|
||||||
* - no existe un título de negocio independiente del código institucional;
|
* no expone título independiente ni fecha prevista de fin.
|
||||||
* - 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.
|
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class F4InspectionVisitsService extends InspectionVisitsService {
|
export class F4InspectionVisitsService extends InspectionVisitsService {
|
||||||
@@ -32,13 +27,13 @@ export class F4InspectionVisitsService extends InspectionVisitsService {
|
|||||||
const response = await super.list(query);
|
const response = await super.list(query);
|
||||||
return {
|
return {
|
||||||
...response,
|
...response,
|
||||||
data: response.data.map((visit) => this.normalizeVisit(visit)),
|
data: response.data.map((visit) => this.normalizeChecklist(visit)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
override async getById(id: string): Promise<InspectionVisitView> {
|
override async getById(id: string): Promise<InspectionVisitView> {
|
||||||
await this.reclassifyCurrentChecklist(id);
|
await this.reclassifyCurrentChecklist(id);
|
||||||
return this.normalizeVisit(await super.getById(id));
|
return this.normalizeChecklist(await super.getById(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
override async create(
|
override async create(
|
||||||
@@ -48,7 +43,7 @@ export class F4InspectionVisitsService extends InspectionVisitsService {
|
|||||||
): Promise<InspectionVisitView> {
|
): Promise<InspectionVisitView> {
|
||||||
const created = await super.create(dto, principal, request);
|
const created = await super.create(dto, principal, request);
|
||||||
await this.reclassifyCurrentChecklist(created.id);
|
await this.reclassifyCurrentChecklist(created.id);
|
||||||
return this.normalizeVisit(await super.getById(created.id));
|
return this.normalizeChecklist(await super.getById(created.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
override async generateChecklist(
|
override async generateChecklist(
|
||||||
@@ -58,27 +53,18 @@ export class F4InspectionVisitsService extends InspectionVisitsService {
|
|||||||
): Promise<InspectionVisitView> {
|
): Promise<InspectionVisitView> {
|
||||||
await super.generateChecklist(id, principal, request);
|
await super.generateChecklist(id, principal, request);
|
||||||
await this.reclassifyCurrentChecklist(id);
|
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 {
|
private normalizeChecklist<T>(visit: T): T {
|
||||||
const normalized = {
|
if (!visit || typeof visit !== 'object' || !('checklist' in visit)) return visit;
|
||||||
...visit,
|
const view = visit as T & InspectionVisitView;
|
||||||
// Compatibilidad de contrato: consumidores antiguos reciben el identificador,
|
view.checklist = {
|
||||||
// no un segundo nombre persistente que pueda divergir.
|
...view.checklist,
|
||||||
title: visit.code,
|
companyOverdue: 0,
|
||||||
plannedEndAt: null,
|
items: view.checklist.items.filter((item) => item.itemKind !== 'COMPANY_OVERDUE'),
|
||||||
} as T;
|
};
|
||||||
|
return view;
|
||||||
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 async reclassifyCurrentChecklist(visitId: string): Promise<void> {
|
private async reclassifyCurrentChecklist(visitId: string): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user