diff --git a/docsfera.json b/docsfera.json index ab3a2c1..9cb09aa 100644 --- a/docsfera.json +++ b/docsfera.json @@ -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": { diff --git a/src/modules/catalog/catalog.service.ts b/src/modules/catalog/catalog.service.ts index 1848dcd..4fd9619 100644 --- a/src/modules/catalog/catalog.service.ts +++ b/src/modules/catalog/catalog.service.ts @@ -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, diff --git a/src/modules/catalog/dtos/index.ts b/src/modules/catalog/dtos/index.ts index ef12e78..59de404 100644 --- a/src/modules/catalog/dtos/index.ts +++ b/src/modules/catalog/dtos/index.ts @@ -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 { diff --git a/src/modules/catalog/share/share.service.ts b/src/modules/catalog/share/share.service.ts index 3e088a6..48f2d5c 100644 --- a/src/modules/catalog/share/share.service.ts +++ b/src/modules/catalog/share/share.service.ts @@ -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,