catalogo: alteracao nas pastas e acrescimo de filtros

This commit is contained in:
Rafael Moraes
2025-12-10 16:51:28 +00:00
parent b0b557246e
commit 2f140d213a
4 changed files with 79 additions and 5 deletions
+20
View File
@@ -3877,6 +3877,16 @@
],
"type": "string"
}
},
{
"name": "owner",
"required": false,
"in": "query",
"description": "ID do usuário owner para filtrar data assets",
"example": "user-id-1,user-id-2",
"schema": {
"type": "string"
}
}
],
"responses": {
@@ -4006,6 +4016,16 @@
],
"type": "string"
}
},
{
"name": "owner",
"required": false,
"in": "query",
"description": "ID do usuário owner para filtrar data assets",
"example": "user-id-1,user-id-2",
"schema": {
"type": "string"
}
}
],
"responses": {
+51 -3
View File
@@ -209,10 +209,58 @@ class CatalogService implements OnModuleInit {
metadata: Metadata,
customer_id: string,
) {
this.logger.info('CatalogService - searchDataAssets');
this.logger.info('CatalogService - searchDataAssets', { query });
const { search, page, size, sort_by, order, ...filters } = query;
this.logger.debug('Extracted filters:', { filters });
if (filters.owner) {
const { users: customer_users } =
await this.userService.findAllUsersByCustomerId(customer_id);
this.logger.info('Available users in database count:', { count: customer_users.length });
this.logger.info('First 5 users:', {
users: customer_users.slice(0, 5).map(u => ({ id: u.id, email: u.email, name: u.name }))
});
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]);
this.logger.info('Owner values to convert:', { ownerValues, ownerFiltersOriginal: filters.owner });
const ownerIds = ownerValues
.map((ownerValue: string) => {
const normalizedOwner = ownerValue.replace(/\s/g, '+');
const user = customer_users.find(u => {
const isIdMatch = u.id === ownerValue;
const isEmailMatch = u.email === ownerValue || u.email === normalizedOwner;
const isNameMatch = u.name === ownerValue || u.name === normalizedOwner;
this.logger.info('Comparing:', {
userId: u.id,
userEmail: u.email,
userName: u.name,
filterValue: ownerValue,
normalizedFilter: normalizedOwner,
idMatch: isIdMatch,
emailMatch: isEmailMatch,
nameMatch: isNameMatch,
});
return isIdMatch || isEmailMatch || isNameMatch;
});
this.logger.info('Looking for owner result:', { ownerValue, found: !!user, userId: user?.id });
return user?.id || ownerValue;
})
.filter((id: string) => id);
if (ownerIds.length > 0) {
filters.owner = ownerIds;
}
}
const { data_assets, total } = await lastValueFrom(
this.catalogReadService.GetAllDataAssets(
{
@@ -404,7 +452,7 @@ class CatalogService implements OnModuleInit {
return data_assets.map((data_asset) => {
const owner = customer_users.find(
(u) => u.id === data_asset.owner,
)?.username;
)?.email;
const roles = [];
const users = [];
@@ -417,7 +465,7 @@ class CatalogService implements OnModuleInit {
const data_asset_users = data_asset?.users || []
for (const user_id of data_asset_users) {
const user = customer_users.find((r) => r.id === user_id);
if (user) users.push({ id: user.id, username: user.username });
if (user) users.push({ id: user.id, email: user.email });
}
return {
...data_asset,
+6
View File
@@ -147,6 +147,12 @@ export class ICatalogAllRequest {
description: 'Tipo de ordenação - `asc`: crescente; `desc`: decrescente ',
})
order?: OrderEnum;
@ApiPropertyOptional({
description: 'ID do usuário owner para filtrar data assets',
example: 'user-id-1,user-id-2',
})
owner?: string;
}
export class ICatalogAllResponse {
+2 -2
View File
@@ -180,7 +180,7 @@ export class ShareService implements OnModuleInit {
return data_assets.map((data_asset) => {
const owner = customer_users.find(
(u) => u.id === data_asset.owner,
)?.username;
)?.email;
const roles = [];
const users = [];
@@ -190,7 +190,7 @@ export class ShareService implements OnModuleInit {
}
for (const user_id of data_asset.users) {
const user = customer_users.find((r) => r.id === user_id);
if (user) users.push({ id: user.id, username: user.username });
if (user) users.push({ id: user.id, email: user.email });
}
return {
...data_asset,