diff --git a/docsfera.json b/docsfera.json index 7fb3e1a..29f2ff3 100644 --- a/docsfera.json +++ b/docsfera.json @@ -4705,10 +4705,10 @@ ] } }, - "/platform/inputs/{inputId}/jobs/{jobId}": { + "/platform/inputs/{inputId}/tables/{tableName}": { "delete": { - "operationId": "PlatformApiController_deleteJob", - "summary": "Delete a job and mark its table as deleted via in-factory", + "operationId": "PlatformApiController_deleteTable", + "summary": "Mark a table as deleted and delete its associated job via platform-api", "parameters": [ { "name": "inputId", @@ -4719,24 +4719,25 @@ } }, { - "name": "jobId", + "name": "tableName", "required": true, "in": "path", "schema": { "type": "string" } + }, + { + "name": "pipelineId", + "required": true, + "in": "query", + "schema": { + "type": "string" + } } ], "responses": { "200": { - "description": "", - "content": { - "application/json": { - "schema": { - "type": "object" - } - } - } + "description": "" } }, "tags": [ diff --git a/package-lock.json b/package-lock.json index 098aea0..a7f9147 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "@aws-sdk/signature-v4": "^3.370.0", "@dadosfera/dadosfera-logs": "^1.0.0-beta.4", "@dadosfera/protospack": "2.5.3", - "@dadosfera/protospack-v2": "^3.40.0-beta.4", + "@dadosfera/protospack-v2": "^3.40.0-beta.5", "@grpc/grpc-js": "^1.9.3", "@grpc/proto-loader": "^0.7.9", "@nestjs/cli": "^9.5.0", @@ -1745,9 +1745,9 @@ } }, "node_modules/@dadosfera/protospack-v2": { - "version": "3.40.0-beta.4", - "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.40.0-beta.4.tgz", - "integrity": "sha512-ftK4edb3fgGw3qLx+cT79cHYL+1gBoWXd8+SBFQXWHBrnxoRKbanBDp5Yn9PbaYZdRMSqTxSKsBwiTyJzLBunQ==", + "version": "3.40.0-beta.5", + "resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.40.0-beta.5.tgz", + "integrity": "sha512-iocKv/XXp2jKAasO5ONgm31cKfLgNsU4pEKZMr6YnR7nQaH11WcW7rnuagNxWoik++wLUqbYyf0bZWRDzMlCPA==", "dependencies": { "@grpc/grpc-js": "^1.9.3", "rxjs": "^7.5.5" diff --git a/package.json b/package.json index e4815e6..18bb538 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@aws-sdk/signature-v4": "^3.370.0", "@dadosfera/dadosfera-logs": "^1.0.0-beta.4", "@dadosfera/protospack": "2.5.3", - "@dadosfera/protospack-v2": "^3.40.0-beta.4", + "@dadosfera/protospack-v2": "^3.40.0-beta.5", "@grpc/grpc-js": "^1.9.3", "@grpc/proto-loader": "^0.7.9", "@nestjs/cli": "^9.5.0", diff --git a/src/modules/pipelinesV2/pipelines.controller.ts b/src/modules/pipelinesV2/pipelines.controller.ts index 71091ad..e91d217 100644 --- a/src/modules/pipelinesV2/pipelines.controller.ts +++ b/src/modules/pipelinesV2/pipelines.controller.ts @@ -54,7 +54,7 @@ import { UpdateInputRequest } from '../inputs/dtos/old_interfaces'; import { Info } from '@dadosfera/protospack-v2/dist/lib/Input/interfaces/entities'; type PipelineTable = { name: string; job_id?: string; is_deleted?: boolean; [key: string]: any }; -type PipelineTablesConfig = { input_id?: string; tables?: PipelineTable[] } | PipelineTable[]; +type PipelineTablesConfig = { input_id?: string; tables: PipelineTable[] }; @ApiTags('PipelinesV2') @ApiHeaders([{ name: 'dadosfera-lang', enum: LanguageEnum, required: false }]) @@ -229,11 +229,8 @@ export class PipelinesController { const pipelineRes = await this.pipelinesClientService.findOne({ id }, metadata); const parsed: PipelineTablesConfig = JSON.parse(pipelineRes.pipeline.config.tables); - const input_id = (parsed as { input_id?: string; tables?: PipelineTable[] })?.input_id; - const normalizedId = id.replace(/-/g, '_'); - const tables: PipelineTable[] = ( - (parsed as { tables?: PipelineTable[] })?.tables ?? (parsed as PipelineTable[]) - ).map((table, index) => ({ ...table, job_id: `${normalizedId}_${index}` })); + const input_id = parsed.input_id; + const tables: PipelineTable[] = parsed.tables ?? []; Object.assign(pipelineRes.pipeline, { transformations: pipelineRes.pipeline.transformations diff --git a/src/modules/platform-api/platform-api.controller.ts b/src/modules/platform-api/platform-api.controller.ts index b880a9b..e850f3e 100644 --- a/src/modules/platform-api/platform-api.controller.ts +++ b/src/modules/platform-api/platform-api.controller.ts @@ -965,42 +965,45 @@ export class PlatformApiController { ); } - @Delete('inputs/:inputId/jobs/:jobId') - @ApiOperation({ summary: 'Delete a job and mark its table as deleted via in-factory' }) + @Delete('inputs/:inputId/tables/:tableName') + @ApiOperation({ summary: 'Mark a table as deleted and delete its associated job via platform-api' }) @RequireAllPermissions(PERMISSIONS_GROUPS.PIPELINE.permissions.DELETE) - async deleteJob( + async deleteTable( @Param('inputId') inputId: string, - @Param('jobId') jobId: string, + @Param('tableName') tableName: string, + @Query('pipelineId') pipelineId: string, @User() user: RequestUser, ) { - const normalizedJobId = this.normalizeJobId(jobId); - - const jobDetails = await this.platformApiService.proxy('GET', `/jobs/${normalizedJobId}`, user); - const tableName: string | undefined = jobDetails?.source_config?.table_name; - - if (!tableName) { - throw new NotFoundException(`Job ${jobId} not found or has no associated table`); - } - const info = { customer_id: user.customer_id, customer: user.customer_name, user_id: user.user_id, }; + this.logger.info('deleteTable: marking table as deleted', { inputId, tableName }); const updatedInput: any = await this.inputsService.markTableDeleted({ input_id: inputId, table_name: tableName, info }); + this.logger.info('deleteTable: table marked as deleted', { inputId, tableName }); try { - await this.platformApiService.proxy('DELETE', `/jobs/${normalizedJobId}`, user); + const normalizedPipelineId = this.normalizeJobId(pipelineId); + this.logger.info('deleteTable: fetching pipeline from platform-api', { pipelineId, normalizedPipelineId }); + const platformPipeline = await this.platformApiService.proxy('GET', `/pipeline/${normalizedPipelineId}`, user); + this.logger.info('deleteTable: pipeline fetched', { jobCount: platformPipeline?.jobs?.length }); - const updatedTable = updatedInput.tables?.find((t: any) => t.name === tableName); - return updatedTable ?? { name: tableName, is_deleted: true }; + const job = platformPipeline?.jobs?.find((j: any) => j.input?.table_name === tableName); + if (!job) throw new NotFoundException(`Job for table '${tableName}' not found in pipeline`); + + this.logger.info('deleteTable: deleting job from platform-api', { jobId: job.job_id }); + await this.platformApiService.proxy('DELETE', `/jobs/${job.job_id}`, user); + this.logger.info('deleteTable: job deleted', { jobId: job.job_id }); + + return { name: tableName, is_deleted: updatedInput.is_deleted ?? true, deleted_at: updatedInput.deleted_at }; } catch (error) { - this.logger.error('deleteJob: platform-api delete failed, attempting rollback', { jobId, tableName, error: error.message }); + this.logger.error('deleteTable: platform-api delete failed, attempting rollback', { tableName, error: error.message }); try { await this.inputsService.unmarkTableDeleted({ input_id: inputId, table_name: tableName, info }); } catch (rollbackError) { - this.logger.error('deleteJob: rollback failed', { jobId, tableName, error: rollbackError.message }); + this.logger.error('deleteTable: rollback failed', { tableName, error: rollbackError.message }); } throw error; } diff --git a/src/services/dynamodb/dynamodb.service.ts b/src/services/dynamodb/dynamodb.service.ts index 90e5efa..0022b35 100644 --- a/src/services/dynamodb/dynamodb.service.ts +++ b/src/services/dynamodb/dynamodb.service.ts @@ -235,52 +235,4 @@ export class DynamoDBService { } } - /** - * Remove a specific table entry from the input document. - * Fetches the current document, removes the matching table, and saves. - */ - async removeInputTable( - clientId: string, - inputId: string, - tableName: string, - ): Promise { - const dynamoTableName = DYNAMODB_CONFIG.inputsTable(); - - this.logger.info('DynamoDB: Removing input table', { - inputId, - tableName, - }); - - const current = await this.findInput(clientId, inputId); - if (!current) { - this.logger.warn('DynamoDB: Input not found for table removal', { inputId }); - return; - } - - const tables = (current.tables || []).filter((t) => t.name !== tableName); - - const putCommand = new PutCommand({ - TableName: dynamoTableName, - Item: { - ...current, - tables, - updated_at: new Date().toISOString(), - }, - }); - - try { - await this.documentClient.send(putCommand); - this.logger.info('DynamoDB: Input table removed successfully', { - inputId, - tableName, - }); - } catch (error) { - this.logger.error('DynamoDB: Failed to remove input table', { - inputId, - tableName, - error: error.message, - }); - throw error; - } - } }