mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-08-26 06:19:38 +00:00
140 lines
4.0 KiB
TypeScript
140 lines
4.0 KiB
TypeScript
import { AutomationService } from '../services/automation.service';
|
|
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
HttpStatus,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
Put,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
|
import {
|
|
AddAutomationDto,
|
|
UpdateAutomationDto,
|
|
UpdateAutomationStatusDto,
|
|
} from '../dtos/automation.dto';
|
|
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
|
import { AutomationParamDto } from '../dtos';
|
|
import { ControllerRoute } from '@app/common/constants/controller-route';
|
|
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
|
import { Permissions } from 'src/decorators/permissions.decorator';
|
|
import { ProjectParam } from '@app/common/dto/project-param.dto';
|
|
|
|
@ApiTags('Automation Module')
|
|
@Controller({
|
|
version: EnableDisableStatusEnum.ENABLED,
|
|
path: ControllerRoute.AUTOMATION.ROUTE,
|
|
})
|
|
export class AutomationController {
|
|
constructor(private readonly automationService: AutomationService) {}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(PermissionsGuard)
|
|
@Permissions('AUTOMATION_ADD')
|
|
@Post()
|
|
@ApiOperation({
|
|
summary: ControllerRoute.AUTOMATION.ACTIONS.ADD_AUTOMATION_SUMMARY,
|
|
description: ControllerRoute.AUTOMATION.ACTIONS.ADD_AUTOMATION_DESCRIPTION,
|
|
})
|
|
async addAutomation(
|
|
@Param() param: ProjectParam,
|
|
@Body() addAutomationDto: AddAutomationDto,
|
|
) {
|
|
const automation = await this.automationService.addAutomation(
|
|
param,
|
|
addAutomationDto,
|
|
);
|
|
return {
|
|
statusCode: HttpStatus.CREATED,
|
|
success: true,
|
|
message: 'Automation added successfully',
|
|
data: automation,
|
|
};
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(PermissionsGuard)
|
|
@Permissions('AUTOMATION_VIEW')
|
|
@Get(':automationUuid')
|
|
@ApiOperation({
|
|
summary: ControllerRoute.AUTOMATION.ACTIONS.GET_AUTOMATION_DETAILS_SUMMARY,
|
|
description:
|
|
ControllerRoute.AUTOMATION.ACTIONS.GET_AUTOMATION_DETAILS_DESCRIPTION,
|
|
})
|
|
async getAutomationDetails(@Param() param: AutomationParamDto) {
|
|
const automation = await this.automationService.getAutomationDetails(param);
|
|
return automation;
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(PermissionsGuard)
|
|
@Permissions('AUTOMATION_DELETE')
|
|
@Delete(':automationUuid')
|
|
@ApiOperation({
|
|
summary: ControllerRoute.AUTOMATION.ACTIONS.DELETE_AUTOMATION_SUMMARY,
|
|
description:
|
|
ControllerRoute.AUTOMATION.ACTIONS.DELETE_AUTOMATION_DESCRIPTION,
|
|
})
|
|
async deleteAutomation(@Param() param: AutomationParamDto) {
|
|
await this.automationService.deleteAutomation(param);
|
|
return {
|
|
statusCode: HttpStatus.OK,
|
|
message: 'Automation Deleted Successfully',
|
|
};
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(PermissionsGuard)
|
|
@Permissions('AUTOMATION_UPDATE')
|
|
@Put(':automationUuid')
|
|
@ApiOperation({
|
|
summary: ControllerRoute.AUTOMATION.ACTIONS.UPDATE_AUTOMATION_SUMMARY,
|
|
description:
|
|
ControllerRoute.AUTOMATION.ACTIONS.UPDATE_AUTOMATION_DESCRIPTION,
|
|
})
|
|
async updateAutomation(
|
|
@Body() updateAutomationDto: UpdateAutomationDto,
|
|
@Param() param: AutomationParamDto,
|
|
) {
|
|
const automation = await this.automationService.updateAutomation(
|
|
updateAutomationDto,
|
|
param,
|
|
);
|
|
return {
|
|
statusCode: HttpStatus.CREATED,
|
|
success: true,
|
|
message: 'Automation updated successfully',
|
|
data: automation,
|
|
};
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(PermissionsGuard)
|
|
@Permissions('AUTOMATION_CONTROL')
|
|
@Patch(':automationUuid')
|
|
@ApiOperation({
|
|
summary:
|
|
ControllerRoute.AUTOMATION.ACTIONS.UPDATE_AUTOMATION_STATUS_SUMMARY,
|
|
description:
|
|
ControllerRoute.AUTOMATION.ACTIONS.UPDATE_AUTOMATION_STATUS_DESCRIPTION,
|
|
})
|
|
async updateAutomationStatus(
|
|
@Body() updateAutomationStatusDto: UpdateAutomationStatusDto,
|
|
@Param() param: AutomationParamDto,
|
|
) {
|
|
await this.automationService.updateAutomationStatus(
|
|
updateAutomationStatusDto,
|
|
param,
|
|
);
|
|
return {
|
|
statusCode: HttpStatus.CREATED,
|
|
success: true,
|
|
message: 'Automation status updated successfully',
|
|
};
|
|
}
|
|
}
|