import { Body, Controller, Get, Inject, Param, Post } from '@nestjs/common'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { AuthenticateCondition, Authenticated, } from 'src/decorators/authentication.decorator'; import { PERMISSIONS_GROUPS } from '../../authentication/permissions.enum'; import { PipelinesService } from './pipelines.service'; import { DadosferaLogger } from '@dadosfera/dadosfera-logs'; import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator'; @ApiInternalOnlyController() @ApiTags('Pipelines') @Controller('pipelines') @Authenticated() @AuthenticateCondition((req, user) => { let action; switch (req.method) { case 'POST': action = 'CREATE'; break; case 'PUT': action = 'UPDATE'; break; default: action = req.method; } return user.permissions.includes( PERMISSIONS_GROUPS.PIPELINE.permissions[action].seqid, ); }) export class PipelinesController { logger: DadosferaLogger; constructor( @Inject(DadosferaLogger) dadosferaLogger: DadosferaLogger, private pipelineService: PipelinesService, ) { this.logger = dadosferaLogger.logger; } @Post('start/:id') @ApiOperation({ deprecated: true, description: 'This method is deprecated. Please use route /pipelinesV2/start/:id instead', }) async activate(@Param('id') id: string, @Body() body) { const { info } = body; this.logger.info( process.env.DEV_URL + `/pipeline/start/${id} - ON START PIPELINE ROUTE`, { user: body.info.user_id, customer: body.info.customer, }, ); const response = await this.pipelineService.runPipeline({ id, info }); return response; } @Get(':id/status') @ApiOperation({ deprecated: true, description: 'This method is deprecated. Please use route /pipelinesV2/:id/status instead', }) async getPipelineStatus(@Body() body, @Param('id') id: string) { body.id = id; this.logger.info( process.env.DEV_URL + `/pipeline/${id} - ON GET PIPELINE STATUS ROUTE`, { user: body.info.user_id, customer: body.info.customer, }, ); const response = await this.pipelineService.getPipelineStatus(body); return response; } }