Corrige creación de Inspección, separa Departamento→Área→Yacimiento, elimina el UPDATE oculto de checklist en lectura, integra Preparación para campo como etapa de Inspección, limita operaciones Android al Yacimiento, preserva scope en edición, auto-incluye Inventarios accionables, valida Operadora a plannedStartAt y recompila Android 0.15.2/vc24 con el ícono exacto de presentación.
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { BadRequestException } from '@nestjs/common';
|
|
import type { EntityManager } from 'typeorm';
|
|
|
|
/**
|
|
* F6.1 keeps territorial levels explicit. operationalAreaId freezes the Area
|
|
* context while scopeAssetId identifies the Yacimiento inspected inside it.
|
|
* Legacy/mobile callers may still use the Area itself as scope until Android
|
|
* supplies a Yacimiento explicitly.
|
|
*/
|
|
export async function validateInspectionPlanningScope(
|
|
manager: EntityManager,
|
|
operationalAreaId: string,
|
|
scopeAssetId: string,
|
|
): Promise<void> {
|
|
if (scopeAssetId === operationalAreaId) return;
|
|
|
|
const [scope] = await manager.query(`
|
|
SELECT 1
|
|
FROM assets yacimiento
|
|
INNER JOIN asset_types type ON type.id=yacimiento.asset_type_id
|
|
WHERE yacimiento.id=$1::uuid
|
|
AND yacimiento.parent_id=$2::uuid
|
|
AND lower(type.code)='yacimiento'
|
|
AND type.is_active=true
|
|
AND yacimiento.information_status<>'INACTIVE'
|
|
LIMIT 1
|
|
`, [scopeAssetId, operationalAreaId]) as Array<{ '?column?': number }>;
|
|
|
|
if (!scope) {
|
|
throw new BadRequestException({
|
|
code: 'INSPECTION_YACIMIENTO_OUTSIDE_AREA',
|
|
message: 'El Yacimiento seleccionado no pertenece al Área indicada',
|
|
});
|
|
}
|
|
}
|