mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-28 22:50:05 +00:00
FEAT: update columns metadata endpoint to accept batch updates and add error handling for missing columns
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user