FIX: Enhance filter handling in BuildDataAssetsFilterTerms to support empty owner condition

This commit is contained in:
viniciusgadea
2025-12-15 12:00:50 -03:00
parent 918c3d7416
commit 288aaeabc0
+14 -11
View File
@@ -240,10 +240,10 @@ class CatalogService implements OnModuleInit {
) {
this.logger.info('CatalogService - searchDataAssets');
const { search, page, size, sort_by, order, ...filters } = query;
if (filters.owner) {
// Verificar se filters.owner existe
if (filters.owner !== undefined && filters.owner !== null) {
const { users: customer_users } =
await this.userService.findAllUsersByCustomerId(customer_id);
@@ -253,7 +253,11 @@ class CatalogService implements OnModuleInit {
? filters.owner.split(',').map((o: string) => o.trim())
: [filters.owner]);
const ownerIds = ownerValues
// Separar "sem owner" (marcador especial __null__) dos owners normais
const hasEmptyOwner = ownerValues.some(v => v === '__null__');
const normalOwners = ownerValues.filter(v => v !== '__null__');
const ownerIds = normalOwners
.map((ownerValue: string) => {
const user = customer_users.find(u =>
u.name === ownerValue || u.email === ownerValue || u.id === ownerValue
@@ -262,13 +266,12 @@ class CatalogService implements OnModuleInit {
})
.filter((id: string) => id);
filters.owner = ownerIds;
this.logger.info('Converted owner names to IDs:', {
original: ownerValues,
converted: ownerIds
});
}
// Se tiver "sem owner", adicionar marcador especial
if (hasEmptyOwner) {
ownerIds.push('__null__');
}
filters.owner = ownerIds.length > 0 ? ownerIds : undefined;
const { data_assets, total } = await lastValueFrom(
this.catalogReadService.GetAllDataAssets(