fix(findings): use only authoritative F5 family catalog
This commit is contained in:
@@ -1,41 +1,65 @@
|
|||||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { DataSource } from 'typeorm';
|
import { DataSource } from 'typeorm';
|
||||||
import type { ListFindingCatalogQueryDto } from './dto/list-finding-catalog-query.dto';
|
import type { ListFindingCatalogQueryDto } from './dto/list-finding-catalog-query.dto';
|
||||||
import { FindingCatalogService } from './finding-catalog.service';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class F3FindingCatalogResolverService {
|
export class F3FindingCatalogResolverService {
|
||||||
constructor(
|
constructor(private readonly dataSource: DataSource) {}
|
||||||
private readonly dataSource: DataSource,
|
|
||||||
private readonly legacyCatalog: FindingCatalogService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async listApplicableForAsset(assetId: string, query: ListFindingCatalogQueryDto) {
|
async listApplicableForAsset(assetId: string, query: ListFindingCatalogQueryDto) {
|
||||||
const [asset] = await this.dataSource.query(`
|
const [asset] = await this.dataSource.query(`
|
||||||
SELECT asset.id,asset.code,asset.name,
|
SELECT asset.id,asset.code,asset.name,
|
||||||
|
type.code AS "typeCode",
|
||||||
asset.inventory_family_id AS "familyId",
|
asset.inventory_family_id AS "familyId",
|
||||||
family.code AS "familyCode",family.name AS "familyName",family.level AS "familyLevel"
|
family.code AS "familyCode",family.name AS "familyName",family.level AS "familyLevel",
|
||||||
|
family.is_active AS "familyActive"
|
||||||
FROM assets asset
|
FROM assets asset
|
||||||
|
JOIN asset_types type ON type.id=asset.asset_type_id
|
||||||
LEFT JOIN inventory_families family ON family.id=asset.inventory_family_id
|
LEFT JOIN inventory_families family ON family.id=asset.inventory_family_id
|
||||||
WHERE asset.id=$1::uuid
|
WHERE asset.id=$1::uuid
|
||||||
`, [assetId]) as Array<{
|
`, [assetId]) as Array<{
|
||||||
id: string;
|
id: string;
|
||||||
code: string;
|
code: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
typeCode: string;
|
||||||
familyId: string | null;
|
familyId: string | null;
|
||||||
familyCode: string | null;
|
familyCode: string | null;
|
||||||
familyName: string | null;
|
familyName: string | null;
|
||||||
familyLevel: string | null;
|
familyLevel: string | null;
|
||||||
|
familyActive: boolean | null;
|
||||||
}>;
|
}>;
|
||||||
if (!asset) {
|
if (!asset) {
|
||||||
throw new NotFoundException({ code: 'ASSET_NOT_FOUND', message: 'Registro de Inventario no encontrado' });
|
throw new NotFoundException({ code: 'ASSET_NOT_FOUND', message: 'Registro de Inventario no encontrado' });
|
||||||
}
|
}
|
||||||
if (!asset.familyId) return this.legacyCatalog.listApplicableForAsset(assetId, query);
|
|
||||||
|
const other = {
|
||||||
|
enabled: true,
|
||||||
|
code: 'OTHER',
|
||||||
|
label: 'OTROS',
|
||||||
|
help: 'Usalo cuando el Hallazgo no exista en el catálogo aplicable. Se enviará una propuesta a revisión de oficina.',
|
||||||
|
};
|
||||||
|
|
||||||
|
// F5: no se mezclan catálogos históricos. Yacimiento no posee familia técnica
|
||||||
|
// en final_modelov2.xlsx, por lo que puede registrar Hallazgos mediante OTROS.
|
||||||
|
if (!asset.familyId || asset.familyActive !== true) {
|
||||||
|
return {
|
||||||
|
asset: { id: asset.id, code: asset.code, name: asset.name },
|
||||||
|
inventoryFamily: null,
|
||||||
|
typeConfigured: false,
|
||||||
|
configurationReason: asset.typeCode.toLowerCase() === 'yacimiento'
|
||||||
|
? 'F5 · Yacimiento sin catálogo precargado: Hallazgos disponibles mediante OTROS.'
|
||||||
|
: 'F5 · El elemento todavía no tiene una clasificación técnica activa.',
|
||||||
|
categories: [],
|
||||||
|
items: [],
|
||||||
|
other,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const filters = [
|
const filters = [
|
||||||
'mapping.inventory_family_id=$1::uuid',
|
'mapping.inventory_family_id=$1::uuid',
|
||||||
'item.is_active=true',
|
'item.is_active=true',
|
||||||
'category.is_active=true',
|
'category.is_active=true',
|
||||||
|
"lower(category.code)='f5model'",
|
||||||
'merge_record.source_item_id IS NULL',
|
'merge_record.source_item_id IS NULL',
|
||||||
];
|
];
|
||||||
const params: unknown[] = [asset.familyId];
|
const params: unknown[] = [asset.familyId];
|
||||||
@@ -83,15 +107,10 @@ export class F3FindingCatalogResolverService {
|
|||||||
level: asset.familyLevel,
|
level: asset.familyLevel,
|
||||||
},
|
},
|
||||||
typeConfigured: true,
|
typeConfigured: true,
|
||||||
configurationReason: `F3.1 · Catálogo del Excel asociado a ${asset.familyName ?? 'la familia técnica'}`,
|
configurationReason: `F5 · Catálogo final_modelov2.xlsx asociado a ${asset.familyName ?? 'la clasificación técnica'}`,
|
||||||
categories,
|
categories,
|
||||||
items,
|
items,
|
||||||
other: {
|
other,
|
||||||
enabled: true,
|
|
||||||
code: 'OTHER',
|
|
||||||
label: 'OTROS',
|
|
||||||
help: 'Usalo cuando el hallazgo no exista en la familia técnica. Se enviará una propuesta a revisión de oficina.',
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user