mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-21 01:09:08 +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');
|
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
|
// Verificar se filters.owner existe
|
||||||
if (filters.owner !== undefined && filters.owner !== null) {
|
if (owner !== undefined && owner !== null) {
|
||||||
const { users: customer_users } =
|
const { users: customer_users } =
|
||||||
await this.userService.findAllUsersByCustomerId(customer_id);
|
await this.userService.findAllUsersByCustomerId(customer_id);
|
||||||
|
|
||||||
const ownerValues = Array.isArray(filters.owner)
|
let ownerValues: string[];
|
||||||
? filters.owner
|
if (Array.isArray(owner)) {
|
||||||
: (typeof filters.owner === 'string' && filters.owner.includes(',')
|
ownerValues = owner;
|
||||||
? filters.owner.split(',').map((o: string) => o.trim())
|
} else if (typeof owner === 'string' && owner.includes(',')) {
|
||||||
: [filters.owner]);
|
ownerValues = owner.split(',').map((o: string) => o.trim());
|
||||||
|
} else {
|
||||||
|
ownerValues = [owner];
|
||||||
|
}
|
||||||
|
|
||||||
// Separar "sem owner" (marcador especial __null__) dos owners normais
|
// Separar "sem owner" (marcador especial null) dos owners normais
|
||||||
const hasEmptyOwner = ownerValues.some(v => v === '__null__');
|
const hasEmptyOwner = ownerValues.some(v => v === 'null');
|
||||||
const normalOwners = ownerValues.filter(v => v !== '__null__');
|
const normalOwners = ownerValues.filter(v => v !== 'null');
|
||||||
|
|
||||||
const ownerIds = normalOwners
|
// Converter nomes de owners para IDs
|
||||||
.map((ownerValue: string) => {
|
const ownerIds = normalOwners.map((ownerValue: string) => {
|
||||||
const user = customer_users.find(u =>
|
const user = customer_users.find(u =>
|
||||||
u.name === ownerValue || u.email === ownerValue || u.id === ownerValue
|
u.name === ownerValue || u.email === ownerValue || u.id === ownerValue
|
||||||
);
|
);
|
||||||
return user ? user.id : ownerValue;
|
return user ? user.id : ownerValue;
|
||||||
})
|
});
|
||||||
.filter((id: string) => id);
|
|
||||||
|
|
||||||
// Se tiver "sem owner", adicionar marcador especial
|
// Se tiver "sem owner", adicionar marcador especial
|
||||||
if (hasEmptyOwner) {
|
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(
|
const { data_assets, total } = await lastValueFrom(
|
||||||
this.catalogReadService.GetAllDataAssets(
|
this.catalogReadService.GetAllDataAssets(
|
||||||
|
|||||||
Reference in New Issue
Block a user