80 lines
2.9 KiB
TypeScript
80 lines
2.9 KiB
TypeScript
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Query, ValidationPipe } from '@nestjs/common';
|
|
import {
|
|
ApiTags,
|
|
ApiOperation,
|
|
ApiCreatedResponse,
|
|
ApiOkResponse,
|
|
ApiNotFoundResponse,
|
|
ApiParam,
|
|
ApiBody,
|
|
ApiBearerAuth,
|
|
ApiQuery,
|
|
} from '@nestjs/swagger';
|
|
import { ScheduleService } from '../providers/schedule.service';
|
|
import { CreateScheduleDto } from '../dto/create-schedule.dto';
|
|
import { UpdateScheduleDto } from '../dto/update-schedule.dto';
|
|
import { FindSchedulesDto } from '../dto/find-schedules.dto';
|
|
import { Schedule } from '../entities/schedule.entity';
|
|
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
|
import { RestId } from 'src/common/decorators/rest-id.decorator';
|
|
|
|
@UseGuards(AdminAuthGuard)
|
|
@ApiBearerAuth()
|
|
@ApiTags('admin/schedules')
|
|
@Controller('admin/schedules')
|
|
export class ScheduleController {
|
|
constructor(private readonly scheduleService: ScheduleService) {}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: 'Create a new schedule' })
|
|
@ApiBody({ type: CreateScheduleDto })
|
|
@ApiCreatedResponse({ description: 'Schedule created successfully', type: Schedule })
|
|
create(@Body() createScheduleDto: CreateScheduleDto, @RestId() restId: string) {
|
|
return this.scheduleService.create(restId, createScheduleDto);
|
|
}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'Get all schedules' })
|
|
@ApiQuery({
|
|
name: 'weekDay',
|
|
required: false,
|
|
type: Number,
|
|
description: 'Filter by week days (0=Sunday, 6=Saturday).',
|
|
})
|
|
@ApiOkResponse({ description: 'List of schedules', type: [Schedule] })
|
|
findAll(
|
|
@Query(new ValidationPipe({ transform: true, whitelist: true })) query: FindSchedulesDto,
|
|
@RestId() restId: string,
|
|
) {
|
|
return this.scheduleService.findAll(restId, query);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Get a schedule by ID' })
|
|
@ApiParam({ name: 'id', description: 'Schedule ID' })
|
|
@ApiOkResponse({ description: 'Schedule details', type: Schedule })
|
|
@ApiNotFoundResponse({ description: 'Schedule not found' })
|
|
findOne(@Param('id') id: string, @RestId() restId: string) {
|
|
return this.scheduleService.findOne(id, restId);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@ApiOperation({ summary: 'Update a schedule' })
|
|
@ApiParam({ name: 'id', description: 'Schedule ID' })
|
|
@ApiBody({ type: UpdateScheduleDto })
|
|
@ApiOkResponse({ description: 'Schedule updated successfully', type: Schedule })
|
|
@ApiNotFoundResponse({ description: 'Schedule not found' })
|
|
update(@Param('id') id: string, @Body() updateScheduleDto: UpdateScheduleDto, @RestId() restId: string) {
|
|
return this.scheduleService.update(id, restId, updateScheduleDto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: 'Delete a schedule' })
|
|
@ApiParam({ name: 'id', description: 'Schedule ID' })
|
|
@ApiOkResponse({ description: 'Schedule deleted successfully' })
|
|
@ApiNotFoundResponse({ description: 'Schedule not found' })
|
|
remove(@Param('id') id: string, @RestId() restId: string) {
|
|
return this.scheduleService.remove(id, restId);
|
|
}
|
|
}
|