2026-06-07 15:40:01 +02:00
import { Body , Controller , Delete , Get , HttpCode , HttpStatus , Param , Patch , Post , Put , Query } from '@nestjs/common' ;
import { ApiExcludeEndpoint , ApiTags } from '@nestjs/swagger' ;
2025-11-14 14:05:05 -06:00
import { Endpoint , HistoryBuilder } from 'src/decorators' ;
import { AuthDto } from 'src/dtos/auth.dto' ;
2026-05-18 11:09:33 -04:00
import {
WorkflowCreateDto ,
WorkflowResponseDto ,
WorkflowSearchDto ,
WorkflowShareResponseDto ,
WorkflowTriggerResponseDto ,
WorkflowUpdateDto ,
} from 'src/dtos/workflow.dto' ;
2025-11-14 14:05:05 -06:00
import { Permission } from 'src/enum' ;
import { Auth , Authenticated } from 'src/middleware/auth.guard' ;
import { WorkflowService } from 'src/services/workflow.service' ;
import { UUIDParamDto } from 'src/validation' ;
@ApiTags ( 'Workflows' )
@Controller ( 'workflows' )
export class WorkflowController {
constructor ( private service : WorkflowService ) { }
@Post ( )
@Authenticated ( { permission : Permission.WorkflowCreate } )
@Endpoint ( {
summary : 'Create a workflow' ,
description : 'Create a new workflow, the workflow can also be created with empty filters and actions.' ,
2026-05-18 11:09:33 -04:00
history : HistoryBuilder.v3 ( ) ,
2025-11-14 14:05:05 -06:00
} )
createWorkflow ( @Auth ( ) auth : AuthDto , @Body ( ) dto : WorkflowCreateDto ) : Promise < WorkflowResponseDto > {
return this . service . create ( auth , dto ) ;
}
@Get ( )
@Authenticated ( { permission : Permission.WorkflowRead } )
@Endpoint ( {
summary : 'List all workflows' ,
description : 'Retrieve a list of workflows available to the authenticated user.' ,
2026-05-18 11:09:33 -04:00
history : HistoryBuilder.v3 ( ) ,
2025-11-14 14:05:05 -06:00
} )
2026-05-18 11:09:33 -04:00
searchWorkflows ( @Auth ( ) auth : AuthDto , @Query ( ) dto : WorkflowSearchDto ) : Promise < WorkflowResponseDto [ ] > {
return this . service . search ( auth , dto ) ;
}
@Get ( 'triggers' )
@Authenticated ( { permission : false } )
@Endpoint ( {
summary : 'List all workflow triggers' ,
description : 'Retrieve a list of all available workflow triggers.' ,
history : HistoryBuilder.v3 ( ) ,
} )
getWorkflowTriggers ( ) : WorkflowTriggerResponseDto [ ] {
return this . service . getTriggers ( ) ;
2025-11-14 14:05:05 -06:00
}
@Get ( ':id' )
@Authenticated ( { permission : Permission.WorkflowRead } )
@Endpoint ( {
summary : 'Retrieve a workflow' ,
description : 'Retrieve information about a specific workflow by its ID.' ,
2026-05-18 11:09:33 -04:00
history : HistoryBuilder.v3 ( ) ,
2025-11-14 14:05:05 -06:00
} )
getWorkflow ( @Auth ( ) auth : AuthDto , @Param ( ) { id } : UUIDParamDto ) : Promise < WorkflowResponseDto > {
return this . service . get ( auth , id ) ;
}
2026-05-18 11:09:33 -04:00
@Get ( ':id/share' )
@Authenticated ( { permission : Permission.WorkflowRead } )
@Endpoint ( {
summary : 'Retrieve a workflow' ,
description : 'Retrieve a workflow details without ids, default values, etc.' ,
history : HistoryBuilder.v3 ( ) ,
} )
getWorkflowForShare ( @Auth ( ) auth : AuthDto , @Param ( ) { id } : UUIDParamDto ) : Promise < WorkflowShareResponseDto > {
return this . service . share ( auth , id ) ;
}
2025-11-14 14:05:05 -06:00
@Put ( ':id' )
@Authenticated ( { permission : Permission.WorkflowUpdate } )
@Endpoint ( {
summary : 'Update a workflow' ,
description :
'Update the information of a specific workflow by its ID. This endpoint can be used to update the workflow name, description, trigger type, filters and actions order, etc.' ,
2026-06-07 15:40:01 +02:00
history : new HistoryBuilder ( ) . added ( 'v3.0.0' ) . deprecated ( 'v3' , { replacementId : 'updateWorkflow' } ) ,
2025-11-14 14:05:05 -06:00
} )
updateWorkflow (
@Auth ( ) auth : AuthDto ,
@Param ( ) { id } : UUIDParamDto ,
@Body ( ) dto : WorkflowUpdateDto ,
) : Promise < WorkflowResponseDto > {
return this . service . update ( auth , id , dto ) ;
}
2026-06-07 15:40:01 +02:00
@Patch ( ':id' )
@ApiExcludeEndpoint ( )
@Authenticated ( { permission : Permission.WorkflowUpdate } )
updateWorkflowV3 (
@Auth ( ) auth : AuthDto ,
@Param ( ) { id } : UUIDParamDto ,
@Body ( ) dto : WorkflowUpdateDto ,
) : Promise < WorkflowResponseDto > {
return this . service . update ( auth , id , dto ) ;
}
2025-11-14 14:05:05 -06:00
@Delete ( ':id' )
@Authenticated ( { permission : Permission.WorkflowDelete } )
@HttpCode ( HttpStatus . NO_CONTENT )
@Endpoint ( {
summary : 'Delete a workflow' ,
description : 'Delete a workflow by its ID.' ,
2026-05-18 11:09:33 -04:00
history : HistoryBuilder.v3 ( ) ,
2025-11-14 14:05:05 -06:00
} )
deleteWorkflow ( @Auth ( ) auth : AuthDto , @Param ( ) { id } : UUIDParamDto ) : Promise < void > {
return this . service . delete ( auth , id ) ;
}
}