mirror of
https://github.com/dadosfera/maestro.git
synced 2026-08-31 19:58:21 +00:00
FIX: Update searchDataAssets to handle owner filtering and convert owner names to IDs
This commit is contained in:
@@ -240,38 +240,44 @@ class CatalogService implements OnModuleInit {
|
||||
) {
|
||||
this.logger.info('CatalogService - searchDataAssets');
|
||||
|
||||
const { search, page, size, sort_by, order, ...filters } = query;
|
||||
const { search, page, size, sort_by, order, owner, ...filters } = query;
|
||||
|
||||
// Verificar se filters.owner existe
|
||||
if (filters.owner !== undefined && filters.owner !== null) {
|
||||
if (owner !== undefined && owner !== null) {
|
||||
const { users: customer_users } =
|
||||
await this.userService.findAllUsersByCustomerId(customer_id);
|
||||
|
||||
const ownerValues = Array.isArray(filters.owner)
|
||||
? filters.owner
|
||||
: (typeof filters.owner === 'string' && filters.owner.includes(',')
|
||||
? filters.owner.split(',').map((o: string) => o.trim())
|
||||
: [filters.owner]);
|
||||
let ownerValues: string[];
|
||||
if (Array.isArray(owner)) {
|
||||
ownerValues = owner;
|
||||
} else if (typeof owner === 'string' && owner.includes(',')) {
|
||||
ownerValues = owner.split(',').map((o: string) => o.trim());
|
||||
} else {
|
||||
ownerValues = [owner];
|
||||
}
|
||||
|
||||
// Separar "sem owner" (marcador especial __null__) dos owners normais
|
||||
const hasEmptyOwner = ownerValues.some(v => v === '__null__');
|
||||
const normalOwners = ownerValues.filter(v => v !== '__null__');
|
||||
// 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
|
||||
);
|
||||
return user ? user.id : ownerValue;
|
||||
})
|
||||
.filter((id: string) => id);
|
||||
// Converter nomes de owners para IDs
|
||||
const ownerIds = normalOwners.map((ownerValue: string) => {
|
||||
const user = customer_users.find(u =>
|
||||
u.name === ownerValue || u.email === ownerValue || u.id === ownerValue
|
||||
);
|
||||
return user ? user.id : ownerValue;
|
||||
});
|
||||
|
||||
// Se tiver "sem owner", adicionar marcador especial
|
||||
if (hasEmptyOwner) {
|
||||
ownerIds.push('__null__');
|
||||
ownerIds.push('null');
|
||||
}
|
||||
|
||||
filters.owner = ownerIds.length > 0 ? ownerIds : undefined;
|
||||
// Adicionar ao filters apenas se houver valores
|
||||
if (ownerIds.length > 0) {
|
||||
filters.owner = ownerIds;
|
||||
}
|
||||
}
|
||||
|
||||
const { data_assets, total } = await lastValueFrom(
|
||||
this.catalogReadService.GetAllDataAssets(
|
||||
|
||||
Reference in New Issue
Block a user