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