F4: decouple verification planning from company response
This commit is contained in:
@@ -30,7 +30,6 @@ interface VerificationVisitView {
|
||||
title: string;
|
||||
status: InspectionVisitStatus;
|
||||
plannedStartAt: Date | null;
|
||||
plannedEndAt: Date | null;
|
||||
}
|
||||
|
||||
export interface VerificationPlanningItem {
|
||||
@@ -39,7 +38,6 @@ export interface VerificationPlanningItem {
|
||||
title: string;
|
||||
status: 'OPEN';
|
||||
nextControlOn: string;
|
||||
companyResponseReceivedOn: string;
|
||||
asset: VerificationContextView & { typeName: string };
|
||||
company: VerificationContextView | null;
|
||||
area: VerificationContextView | null;
|
||||
@@ -75,7 +73,6 @@ interface LockedFindingRow {
|
||||
areaId: string | null;
|
||||
areaCode: string | null;
|
||||
areaName: string | null;
|
||||
companyResponseReceivedOn: string | null;
|
||||
nextControlOn: string | null;
|
||||
status: string;
|
||||
}
|
||||
@@ -93,7 +90,6 @@ export class InspectionVerificationsService {
|
||||
const values: unknown[] = [];
|
||||
const baseFilters = [
|
||||
`finding.status = 'OPEN'`,
|
||||
`finding.company_response_received_on IS NOT NULL`,
|
||||
`finding.next_control_on IS NOT NULL`,
|
||||
`COALESCE((
|
||||
SELECT latest_verification.outcome
|
||||
@@ -134,8 +130,7 @@ export class InspectionVerificationsService {
|
||||
visit.code,
|
||||
visit.title,
|
||||
visit.status,
|
||||
visit.planned_start_at AS "plannedStartAt",
|
||||
visit.planned_end_at AS "plannedEndAt"
|
||||
visit.planned_start_at AS "plannedStartAt"
|
||||
FROM inspection_finding_verification_visits verification_link
|
||||
INNER JOIN inspection_visits visit ON visit.id = verification_link.visit_id
|
||||
WHERE verification_link.finding_id = finding.id
|
||||
@@ -181,7 +176,6 @@ export class InspectionVerificationsService {
|
||||
finding.title,
|
||||
finding.status,
|
||||
finding.next_control_on AS "nextControlOn",
|
||||
finding.company_response_received_on AS "companyResponseReceivedOn",
|
||||
jsonb_build_object(
|
||||
'id', asset.id,
|
||||
'code', asset.code,
|
||||
@@ -209,8 +203,7 @@ export class InspectionVerificationsService {
|
||||
'code', verification_visit.code,
|
||||
'title', verification_visit.title,
|
||||
'status', verification_visit.status,
|
||||
'plannedStartAt', verification_visit."plannedStartAt",
|
||||
'plannedEndAt', verification_visit."plannedEndAt"
|
||||
'plannedStartAt', verification_visit."plannedStartAt"
|
||||
) END AS "verificationVisit"
|
||||
FROM inspection_findings finding
|
||||
${joins}
|
||||
@@ -503,7 +496,6 @@ export class InspectionVerificationsService {
|
||||
finding.title,
|
||||
finding.status,
|
||||
finding.asset_id AS "assetId",
|
||||
finding.company_response_received_on AS "companyResponseReceivedOn",
|
||||
finding.next_control_on AS "nextControlOn",
|
||||
asset.code AS "assetCode",
|
||||
asset.name AS "assetName",
|
||||
@@ -524,13 +516,11 @@ export class InspectionVerificationsService {
|
||||
if (rows.length !== findingIds.length) {
|
||||
throw new NotFoundException({ code: 'VERIFICATION_FINDING_NOT_FOUND', message: 'Uno o más hallazgos ya no están disponibles' });
|
||||
}
|
||||
const invalid = rows.find((row) =>
|
||||
row.status !== 'OPEN' || !row.companyResponseReceivedOn || !row.nextControlOn,
|
||||
);
|
||||
const invalid = rows.find((row) => row.status !== 'OPEN' || !row.nextControlOn);
|
||||
if (invalid) {
|
||||
throw new ConflictException({
|
||||
code: 'VERIFICATION_FINDING_NOT_READY',
|
||||
message: `${invalid.code} no está listo para una verificación planificada`,
|
||||
message: `${invalid.code} necesita estar abierto y tener una fecha de control para planificar su verificación`,
|
||||
});
|
||||
}
|
||||
const missingContext = rows.find((row) => !row.companyId || !row.areaId);
|
||||
@@ -587,7 +577,6 @@ export class InspectionVerificationsService {
|
||||
operatorCompanyId: companyId,
|
||||
leadInspectorUserId: null,
|
||||
plannedStartAt,
|
||||
plannedEndAt: null,
|
||||
actualStartedAt: null,
|
||||
actualClosedAt: null,
|
||||
instructions,
|
||||
@@ -650,7 +639,6 @@ export class InspectionVerificationsService {
|
||||
code: visit.code,
|
||||
status: visit.status,
|
||||
plannedStartAt: visit.plannedStartAt,
|
||||
plannedEndAt: visit.plannedEndAt,
|
||||
companyId,
|
||||
areaId,
|
||||
findingIds,
|
||||
@@ -665,7 +653,6 @@ export class InspectionVerificationsService {
|
||||
title: visit.title,
|
||||
status: visit.status,
|
||||
plannedStartAt: visit.plannedStartAt,
|
||||
plannedEndAt: visit.plannedEndAt,
|
||||
},
|
||||
company: { id: companyId, code: rows[0]?.companyCode ?? '', name: companyName },
|
||||
area: { id: areaId, code: rows[0]?.areaCode ?? '', name: areaName },
|
||||
@@ -719,9 +706,6 @@ export class InspectionVerificationsService {
|
||||
'title', finding.title,
|
||||
'description', finding.description,
|
||||
'correctionDueOn', finding.correction_due_on,
|
||||
'companyResponse', finding.company_response,
|
||||
'companyResponseReceivedOn', finding.company_response_received_on,
|
||||
'companyCommittedCorrectionOn', finding.company_committed_correction_on,
|
||||
'nextControlOn', finding.next_control_on,
|
||||
'currentVersion', finding.current_version,
|
||||
'verification', JSONB_BUILD_OBJECT(
|
||||
@@ -759,5 +743,4 @@ export class InspectionVerificationsService {
|
||||
]);
|
||||
return versionNumber;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user