mirror of
https://github.com/dadosfera/maestro.git
synced 2026-12-05 21:30:06 +00:00
FEAT: update columns metadata endpoint to accept batch updates and add error handling for missing columns
This commit is contained in:
+2
-4
@@ -5922,11 +5922,9 @@
|
||||
"access-token": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/catalog/data-asset/{id}/columns-metadata/description": {
|
||||
},
|
||||
"patch": {
|
||||
"operationId": "CatalogController_updateColumnDescription",
|
||||
"operationId": "CatalogController_updateColumnsMetadata",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "dadosfera-lang",
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user