From f3af297a71c82a461a8b15f36d1ab71c7464c99b Mon Sep 17 00:00:00 2001 From: enlineawork Date: Mon, 7 Sep 2026 10:17:19 -0300 Subject: [PATCH] F3.1: consultar Hallazgos asociados por familia --- .../inventory-family-catalog.service.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 api-v3/src/asset-master/inventory-family-catalog.service.ts diff --git a/api-v3/src/asset-master/inventory-family-catalog.service.ts b/api-v3/src/asset-master/inventory-family-catalog.service.ts new file mode 100644 index 0000000..0c76928 --- /dev/null +++ b/api-v3/src/asset-master/inventory-family-catalog.service.ts @@ -0,0 +1,39 @@ +import { Injectable, NotFoundException } from '@nestjs/common'; +import { DataSource } from 'typeorm'; + +@Injectable() +export class InventoryFamilyCatalogService { + constructor(private readonly dataSource: DataSource) {} + + async findings(familyId: string) { + const [family] = await this.dataSource.query(` + SELECT id,code,name,level,information_labels AS "informationLabels" + FROM inventory_families + WHERE id=$1::uuid AND is_active=true + `, [familyId]) as Array<{ + id: string; + code: string; + name: string; + level: string; + informationLabels: string[]; + }>; + if (!family) { + throw new NotFoundException({ + code: 'INVENTORY_FAMILY_NOT_FOUND', + message: 'La familia técnica no existe', + }); + } + const items = await this.dataSource.query(` + SELECT item.id,item.code,item.source_number AS "sourceNumber",item.title, + item.legal_basis AS "legalBasis",item.glossary,item.suggested_severity AS "suggestedSeverity", + category.id AS "categoryId",category.code AS "categoryCode",category.name AS "categoryName" + FROM finding_catalog_item_inventory_families mapping + JOIN finding_catalog_items item ON item.id=mapping.catalog_item_id + JOIN finding_categories category ON category.id=item.category_id + WHERE mapping.inventory_family_id=$1::uuid + AND item.is_active=true AND category.is_active=true + ORDER BY category.sort_order,item.source_number,item.title + `, [familyId]); + return { family, items, count: items.length }; + } +}