diff --git a/docsfera.json b/docsfera.json index e4d97f7..c978f88 100644 --- a/docsfera.json +++ b/docsfera.json @@ -5922,11 +5922,9 @@ "access-token": [] } ] - } - }, - "/catalog/data-asset/{id}/columns-metadata/description": { + }, "patch": { - "operationId": "CatalogController_updateColumnDescription", + "operationId": "CatalogController_updateColumnsMetadata", "parameters": [ { "name": "dadosfera-lang", diff --git a/src/modules/catalog/catalog.controller.ts b/src/modules/catalog/catalog.controller.ts index 1941aa5..9484f1b 100644 --- a/src/modules/catalog/catalog.controller.ts +++ b/src/modules/catalog/catalog.controller.ts @@ -432,22 +432,44 @@ export class CatalogController { return { columns_metadata }; } - @Patch('data-asset/:id/columns-metadata/description') + @Patch('data-asset/:id/columns-metadata') @RequireSomePermission( PERMISSIONS_GROUPS.CATALOG.permissions.UPDATE, PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER, ) - async updateColumnDescription( + async updateColumnsMetadata( @User() user: RequestUser, @Language() language: LanguageEnum, @Param('id') id: string, - @Body() body: { column_name: string; description: string }, + @Body() + body: { + column_name?: string; + description?: string; + columns?: { column_name: string; description: string }[]; + }, ): Promise<{ success: boolean }> { const { customer_name, customer_id, user_id, username } = user; - this.logger.info(`/catalog - update column description`, { + // Accept both a single { column_name, description } and a batch { columns: [...] }. + const columns = Array.isArray(body.columns) + ? body.columns + : [{ column_name: body.column_name, description: body.description }]; + + // column_name and description must be strings — the frontend renders the + // description as text and breaks on non-string values (e.g. numbers). + for (const column of columns) { + if (typeof column?.column_name !== 'string' || !column.column_name.trim()) { + throw new BadRequestException('column_name must be a non-empty string'); + } + if (typeof column?.description !== 'string') { + throw new BadRequestException('description must be a string'); + } + } + + this.logger.info(`/catalog - update columns metadata`, { user_id, customer_name, + columns_count: columns.length, }); const metadata = PackTheMetadata({ @@ -458,12 +480,7 @@ export class CatalogController { language, }); - await this.catalogService.updateColumnDescription( - id, - body.column_name, - body.description, - metadata, - ); + await this.catalogService.updateColumnsDescriptions(id, columns, metadata); return { success: true }; } diff --git a/src/modules/catalog/catalog.service.ts b/src/modules/catalog/catalog.service.ts index 94ea9c6..0683106 100644 --- a/src/modules/catalog/catalog.service.ts +++ b/src/modules/catalog/catalog.service.ts @@ -463,10 +463,9 @@ class CatalogService implements OnModuleInit { return result; } - async updateColumnDescription( + async updateColumnsDescriptions( id: string, - column_name: string, - description: string, + columns: { column_name: string; description: string }[], metadata: Metadata, ) { await lastValueFrom( @@ -474,7 +473,7 @@ class CatalogService implements OnModuleInit { { id, changes: JSON.stringify({ - column_description: { column_name, description }, + column_descriptions: columns, }), }, metadata, diff --git a/src/utils/ErrorBuilder.ts b/src/utils/ErrorBuilder.ts index 49171ee..7e48cb5 100644 --- a/src/utils/ErrorBuilder.ts +++ b/src/utils/ErrorBuilder.ts @@ -315,6 +315,14 @@ export function EnrichErrorCode(code: string) { 'Tente realizar a ação novamente. Caso o erro persista, entre em contato com o suporte', code, }; + case ErrorCodes.CATALOG.COLUMN_NOT_FOUND: + return { + statusCode: HttpStatus.NOT_FOUND, + error: 'Coluna não encontrada', + message: + 'Uma ou mais colunas informadas não existem neste ativo. Verifique os nomes e tente novamente.', + code, + }; case ErrorCodes.CATALOG.PREVIEW_TOO_BIG: return { statusCode: HttpStatus.INTERNAL_SERVER_ERROR, diff --git a/src/utils/errorCodes.ts b/src/utils/errorCodes.ts index a5856bd..c6f41f9 100644 --- a/src/utils/errorCodes.ts +++ b/src/utils/errorCodes.ts @@ -74,6 +74,7 @@ const CATALOG = { DATA_ASSET_NOT_FOUND: 'CATALOG.DATA_ASSET_NOT_FOUND', PREVIEW_TOO_BIG: 'CATALOG.PREVIEW_TOO_BIG', METADATA_TOO_BIG: 'CATALOG.METADATA_TOO_BIG', + COLUMN_NOT_FOUND: 'CATALOG.COLUMN_NOT_FOUND', }; const IDENTITY_PROVIDER = { INVALID_RESPONSE: 'IDENTITY_PROVIDER.INVALID_RESPONSE',