fix(F6.1): resolve operators at planned inspection date
This commit is contained in:
@@ -62,6 +62,35 @@ export class InspectionPlanningHierarchyService {
|
|||||||
return { data };
|
return { data };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async operatorsForArea(
|
||||||
|
areaId: string,
|
||||||
|
at?: string,
|
||||||
|
): Promise<{ data: InspectionPlanningHierarchyItem[] }> {
|
||||||
|
await this.requireType(areaId, 'area', 'El Área seleccionada no es válida');
|
||||||
|
const effectiveAt = at ? new Date(at) : new Date();
|
||||||
|
if (!Number.isFinite(effectiveAt.getTime())) {
|
||||||
|
throw new BadRequestException({
|
||||||
|
code: 'INSPECTION_PLANNING_DATE_INVALID',
|
||||||
|
message: 'La fecha de planificación no es válida',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const data = await this.dataSource.query(`
|
||||||
|
SELECT DISTINCT company.id, company.code, company.name
|
||||||
|
FROM area_company_relations relation
|
||||||
|
INNER JOIN assets company ON company.id=relation.company_id
|
||||||
|
INNER JOIN asset_types type ON type.id=company.asset_type_id
|
||||||
|
WHERE relation.area_id=$1::uuid
|
||||||
|
AND relation.relation_role='OPERATOR'
|
||||||
|
AND relation.valid_from <= $2::timestamptz
|
||||||
|
AND (relation.valid_until IS NULL OR relation.valid_until > $2::timestamptz)
|
||||||
|
AND type.operational_role='COMPANY'
|
||||||
|
AND type.is_active=true
|
||||||
|
AND company.information_status<>'INACTIVE'
|
||||||
|
ORDER BY company.name, company.code
|
||||||
|
`, [areaId, effectiveAt]) as InspectionPlanningHierarchyItem[];
|
||||||
|
return { data };
|
||||||
|
}
|
||||||
|
|
||||||
private async requireType(id: string, typeCode: string, message: string): Promise<void> {
|
private async requireType(id: string, typeCode: string, message: string): Promise<void> {
|
||||||
const [row] = await this.dataSource.query(`
|
const [row] = await this.dataSource.query(`
|
||||||
SELECT 1
|
SELECT 1
|
||||||
@@ -77,4 +106,4 @@ export class InspectionPlanningHierarchyService {
|
|||||||
throw new BadRequestException({ code: 'INSPECTION_PLANNING_HIERARCHY_INVALID', message });
|
throw new BadRequestException({ code: 'INSPECTION_PLANNING_HIERARCHY_INVALID', message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user