Files
backend/src/scene/controllers/scene.controller.ts
2025-03-24 02:32:44 +03:00

141 lines
4.1 KiB
TypeScript

import { SceneService } from '../services/scene.service';
import {
Body,
Controller,
Delete,
Get,
HttpStatus,
Param,
Post,
Put,
Req,
UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import {
AddSceneIconDto,
AddSceneTapToRunDto,
UpdateSceneTapToRunDto,
} from '../dtos/scene.dto';
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
import { SceneParamDto } from '../dtos';
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
import { ControllerRoute } from '@app/common/constants/controller-route';
import { PermissionsGuard } from 'src/guards/permissions.guard';
import { Permissions } from 'src/decorators/permissions.decorator';
@ApiTags('Scene Module')
@Controller({
version: EnableDisableStatusEnum.ENABLED,
path: ControllerRoute.SCENE.ROUTE,
})
export class SceneController {
constructor(private readonly sceneService: SceneService) {}
@ApiBearerAuth()
@UseGuards(PermissionsGuard)
@Permissions('SCENES_ADD')
@Post('tap-to-run')
@ApiOperation({
summary: ControllerRoute.SCENE.ACTIONS.CREATE_TAP_TO_RUN_SCENE_SUMMARY,
description:
ControllerRoute.SCENE.ACTIONS.CREATE_TAP_TO_RUN_SCENE_DESCRIPTION,
})
async addTapToRunScene(
@Body() addSceneTapToRunDto: AddSceneTapToRunDto,
@Req() req: any,
): Promise<BaseResponseDto> {
const projectUuid = req.user.project.uuid;
return await this.sceneService.createScene(
addSceneTapToRunDto,
projectUuid,
);
}
@ApiBearerAuth()
@UseGuards(PermissionsGuard)
@Permissions('SCENES_DELETE')
@Delete('tap-to-run/:sceneUuid')
@ApiOperation({
summary: ControllerRoute.SCENE.ACTIONS.DELETE_TAP_TO_RUN_SCENE_SUMMARY,
description:
ControllerRoute.SCENE.ACTIONS.DELETE_TAP_TO_RUN_SCENE_DESCRIPTION,
})
async deleteTapToRunScene(
@Param() param: SceneParamDto,
): Promise<BaseResponseDto> {
return await this.sceneService.deleteScene(param);
}
@ApiBearerAuth()
@UseGuards(PermissionsGuard)
@Permissions('SCENES_CONTROL')
@Post('tap-to-run/:sceneUuid/trigger')
@ApiOperation({
summary: ControllerRoute.SCENE.ACTIONS.TRIGGER_TAP_TO_RUN_SCENE_SUMMARY,
description:
ControllerRoute.SCENE.ACTIONS.TRIGGER_TAP_TO_RUN_SCENE_DESCRIPTION,
})
async triggerTapToRunScene(@Param() param: SceneParamDto) {
return await this.sceneService.triggerTapToRunScene(param.sceneUuid);
}
@ApiBearerAuth()
@UseGuards(PermissionsGuard)
@Permissions('SCENES_VIEW')
@Get('tap-to-run/:sceneUuid')
@ApiOperation({
summary: ControllerRoute.SCENE.ACTIONS.GET_TAP_TO_RUN_SCENE_SUMMARY,
description: ControllerRoute.SCENE.ACTIONS.GET_TAP_TO_RUN_SCENE_DESCRIPTION,
})
async getTapToRunSceneDetails(
@Param() param: SceneParamDto,
): Promise<BaseResponseDto> {
return await this.sceneService.getSceneByUuid(param.sceneUuid);
}
@ApiBearerAuth()
@UseGuards(PermissionsGuard)
@Permissions('SCENES_UPDATE')
@Put('tap-to-run/:sceneUuid')
@ApiOperation({
summary: ControllerRoute.SCENE.ACTIONS.UPDATE_TAP_TO_RUN_SCENE_SUMMARY,
description:
ControllerRoute.SCENE.ACTIONS.UPDATE_TAP_TO_RUN_SCENE_DESCRIPTION,
})
async updateTapToRunScene(
@Body() updateSceneTapToRunDto: UpdateSceneTapToRunDto,
@Param() param: SceneParamDto,
@Req() req: any,
) {
const projectUuid = req.user.project.uuid;
return await this.sceneService.updateTapToRunScene(
updateSceneTapToRunDto,
param.sceneUuid,
projectUuid,
);
}
@ApiBearerAuth()
@UseGuards(PermissionsGuard)
@Permissions('SCENES_ADD')
@Post('icon')
async addSceneIcon(@Body() addSceneIconDto: AddSceneIconDto) {
const tapToRunScene = await this.sceneService.addSceneIcon(addSceneIconDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Icon added successfully',
data: tapToRunScene,
};
}
@ApiBearerAuth()
@UseGuards(PermissionsGuard)
@Permissions('SCENES_VIEW')
@Get('icon')
async getAllIcons() {
const icons = await this.sceneService.getAllIcons();
return icons;
}
}