F3.1: consultar Hallazgos asociados por familia
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user