mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-24 00:57:55 +00:00
147 lines
3.9 KiB
TypeScript
147 lines
3.9 KiB
TypeScript
import { ScheduleService } from '../services/schedule.service';
|
|
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Param,
|
|
HttpStatus,
|
|
UseGuards,
|
|
Put,
|
|
Delete,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
|
import {
|
|
AddScheduleDto,
|
|
EnableScheduleDto,
|
|
GetScheduleDeviceDto,
|
|
UpdateScheduleDto,
|
|
} from '../dtos/schedule.dto';
|
|
|
|
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
|
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
|
import { ControllerRoute } from '@app/common/constants/controller-route';
|
|
|
|
@ApiTags('Schedule Module')
|
|
@Controller({
|
|
version: EnableDisableStatusEnum.ENABLED,
|
|
path: ControllerRoute.SCHEDULE.ROUTE,
|
|
})
|
|
export class ScheduleController {
|
|
constructor(private readonly scheduleService: ScheduleService) {}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Post(':deviceUuid')
|
|
@ApiOperation({
|
|
summary: ControllerRoute.SCHEDULE.ACTIONS.ADD_DEVICE_SCHEDULE_SUMMARY,
|
|
description:
|
|
ControllerRoute.SCHEDULE.ACTIONS.ADD_DEVICE_SCHEDULE_DESCRIPTION,
|
|
})
|
|
async addDeviceSchedule(
|
|
@Param('deviceUuid') deviceUuid: string,
|
|
@Body() addScheduleDto: AddScheduleDto,
|
|
) {
|
|
const schedule = await this.scheduleService.addDeviceSchedule(
|
|
deviceUuid,
|
|
addScheduleDto,
|
|
);
|
|
|
|
return {
|
|
statusCode: HttpStatus.CREATED,
|
|
success: true,
|
|
message: 'Schedule added successfully',
|
|
data: schedule,
|
|
};
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Get(':deviceUuid')
|
|
@ApiOperation({
|
|
summary:
|
|
ControllerRoute.SCHEDULE.ACTIONS.GET_DEVICE_SCHEDULE_BY_CATEGORY_SUMMARY,
|
|
description:
|
|
ControllerRoute.SCHEDULE.ACTIONS
|
|
.GET_DEVICE_SCHEDULE_BY_CATEGORY_DESCRIPTION,
|
|
})
|
|
async getDeviceScheduleByCategory(
|
|
@Param('deviceUuid') deviceUuid: string,
|
|
@Query() query: GetScheduleDeviceDto,
|
|
) {
|
|
return await this.scheduleService.getDeviceScheduleByCategory(
|
|
deviceUuid,
|
|
query.category,
|
|
);
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Delete(':deviceUuid/:scheduleId')
|
|
@ApiOperation({
|
|
summary: ControllerRoute.SCHEDULE.ACTIONS.DELETE_DEVICE_SCHEDULE_SUMMARY,
|
|
description:
|
|
ControllerRoute.SCHEDULE.ACTIONS.DELETE_DEVICE_SCHEDULE_DESCRIPTION,
|
|
})
|
|
async deleteDeviceSchedule(
|
|
@Param('deviceUuid') deviceUuid: string,
|
|
@Param('scheduleId') scheduleId: string,
|
|
) {
|
|
await this.scheduleService.deleteDeviceSchedule(deviceUuid, scheduleId);
|
|
return {
|
|
statusCode: HttpStatus.CREATED,
|
|
success: true,
|
|
message: 'Schedule deleted successfully',
|
|
};
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Put('enable/:deviceUuid')
|
|
@ApiOperation({
|
|
summary: ControllerRoute.SCHEDULE.ACTIONS.ENABLE_DEVICE_SCHEDULE_SUMMARY,
|
|
description:
|
|
ControllerRoute.SCHEDULE.ACTIONS.ENABLE_DEVICE_SCHEDULE_DESCRIPTION,
|
|
})
|
|
async enableDeviceSchedule(
|
|
@Param('deviceUuid') deviceUuid: string,
|
|
@Body() enableScheduleDto: EnableScheduleDto,
|
|
) {
|
|
await this.scheduleService.enableDeviceSchedule(
|
|
deviceUuid,
|
|
enableScheduleDto,
|
|
);
|
|
return {
|
|
statusCode: HttpStatus.CREATED,
|
|
success: true,
|
|
message: 'Schedule updated successfully',
|
|
};
|
|
}
|
|
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Put(':deviceUuid')
|
|
@ApiOperation({
|
|
summary: ControllerRoute.SCHEDULE.ACTIONS.UPDATE_DEVICE_SCHEDULE_SUMMARY,
|
|
description:
|
|
ControllerRoute.SCHEDULE.ACTIONS.UPDATE_DEVICE_SCHEDULE_DESCRIPTION,
|
|
})
|
|
async updateDeviceSchedule(
|
|
@Param('deviceUuid') deviceUuid: string,
|
|
@Body() updateScheduleDto: UpdateScheduleDto,
|
|
) {
|
|
const schedule = await this.scheduleService.updateDeviceSchedule(
|
|
deviceUuid,
|
|
updateScheduleDto,
|
|
);
|
|
|
|
return {
|
|
statusCode: HttpStatus.CREATED,
|
|
success: true,
|
|
message: 'Schedule updated successfully',
|
|
data: schedule,
|
|
};
|
|
}
|
|
}
|