From c21d977f7c6fba15a502465dee1517fbb725e895 Mon Sep 17 00:00:00 2001 From: viniciusgadea Date: Tue, 9 Dec 2025 14:51:25 -0300 Subject: [PATCH] FEAT: enhance catalog service to support any asset type in data docs creation --- src/modules/catalog/catalog.controller.ts | 27 +++++++++++--- src/modules/catalog/catalog.service.ts | 45 ++++++++++++++++++----- src/modules/catalog/dtos/index.ts | 7 ++++ 3 files changed, 65 insertions(+), 14 deletions(-) diff --git a/src/modules/catalog/catalog.controller.ts b/src/modules/catalog/catalog.controller.ts index b87829b..13bcf42 100644 --- a/src/modules/catalog/catalog.controller.ts +++ b/src/modules/catalog/catalog.controller.ts @@ -439,7 +439,13 @@ export class CatalogController { language, }); - const docs = await this.catalogService.getDataDocs(id, metadata); + const { data_asset } = await this.catalogService.getOneDataAsset({ + customer_id, + id, + metadata, + }); + + const docs = await this.catalogService.getDataDocs(id, data_asset.data_asset_type, metadata); return { docs }; } @@ -487,21 +493,32 @@ export class CatalogController { @Headers() headers, @Param('id') table_id: string, @Body('docs') docs: string, + @Query('asset_type') asset_type: string, ) { - const { user_id, customer_name } = user; + const { user_id, customer_name, customer_id, username } = user; + + const metadata = PackTheMetadata({ + customer_id, + customer_name, + user_id, + username, + }); - this.logger.info(`/catalog - ON GET DATA DOCS ROUTE`, { + this.logger.info(`/catalog - ON POST DATA DOCS ROUTE`, { user_id, customer_name, }); - const res = await this.catalogService.createDataDocs({ + const body = { table_id, docs, + asset_type, info: { customer: customer_name, }, - }); + } + + const res = await this.catalogService.createDataDocs(body, metadata); return res; } diff --git a/src/modules/catalog/catalog.service.ts b/src/modules/catalog/catalog.service.ts index 1848dcd..16cc4ab 100644 --- a/src/modules/catalog/catalog.service.ts +++ b/src/modules/catalog/catalog.service.ts @@ -24,9 +24,11 @@ import { CatalogClientConfiguration } from './catalog-client'; import { UsersService } from '../users/users.service'; import { RolesService } from '../roles/roles.service'; import { Metadata } from '@grpc/grpc-js'; +import { PackTheMetadata } from 'src/utils/PackTheMetadata'; import { AssetReporter, BatchRemoveRlsRulesRequest, + CreateDataDocsDTO, IUpdateDataRequest, TriggerCatalogReq, } from './dtos'; @@ -337,9 +339,11 @@ class CatalogService implements OnModuleInit { return { data_asset: asset[0] }; } - async getDataDocs(id: string, metadata: Metadata) { + async getDataDocs(id: string, assetType: string, metadata: Metadata) { + const requestType = assetType === 'dataset' ? undefined : assetType; + const { documentation } = await lastValueFrom( - this.catalogReadService.GetDatasetDoc({ id, type: undefined }, metadata), + this.catalogReadService.GetDatasetDoc({ id, type: requestType }, metadata), ); const docs = JSON.parse(documentation); @@ -368,13 +372,36 @@ class CatalogService implements OnModuleInit { return result; } - async createDataDocs(body) { - const nimbusUrl = this._getNimbusUrl(body); - const { data } = await axios.post( - `${nimbusUrl}/api/catalog/data-docs/`, - body, - ); - return data; + async createDataDocs(body: CreateDataDocsDTO, metadata: Metadata) { + if (body.asset_type === 'table' || body.asset_type === 'view') { + const nimbusUrl = this._getNimbusUrl(body); + const { data } = await axios.post( + `${nimbusUrl}/api/catalog/data-docs/`, + body, + ); + return data; + } + + try { + const response: any = await lastValueFrom( + this.catalogWriteService.UpdateDataAssetDoc( + { + id: body.table_id, + docs: body.docs, + }, + metadata, + ), + ); + + return response; + + } catch (error) { + this.logger.error('Error creating data asset docs:', error); + throw new HttpException( + 'Failed to create data asset documentation', + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } } async findAllTags(data, metadata) { diff --git a/src/modules/catalog/dtos/index.ts b/src/modules/catalog/dtos/index.ts index ef12e78..4989672 100644 --- a/src/modules/catalog/dtos/index.ts +++ b/src/modules/catalog/dtos/index.ts @@ -328,3 +328,10 @@ export type AssetReporter = { created_at: string; tags: string; } + +export type CreateDataDocsDTO = { + table_id: string; + docs: string; + asset_type: string; + +} \ No newline at end of file