import { BadRequestException, Body, Controller, HttpCode, HttpStatus, Inject, Post, Req, UseGuards, } from '@nestjs/common'; import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard'; import { WorkflowAutomationService } from '../service/workflow-automation.service'; @Controller('/workflow-automation') @UseGuards(JwtAuthGuard) export class WorkflowAutomationController { constructor( @Inject('WorkflowAutomationService') private readonly workflowAutomationService: WorkflowAutomationService, ) {} /** * Endpoint to update the sequence of workflow automations. * Accepts an array of objects with `id` and `sequence`. */ @Post('/updateSequence') @HttpCode(HttpStatus.OK) async updateSequence( @Body() body: any, @Req() req: Request & { user?: any }, ) { const loggedInUser = req.user?.userData; if (!Array.isArray(body) || body.length === 0) { throw new BadRequestException( 'Invalid input. Expected a non-empty array.', ); } return this.workflowAutomationService.updateSequence(body, loggedInUser); } }