89 lines
2.5 KiB
TypeScript
89 lines
2.5 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Body,
|
|
Param,
|
|
Patch,
|
|
Delete,
|
|
Query,
|
|
ParseIntPipe,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { CalendarService } from './calendar.service';
|
|
import { GetCalendarDto } from './dto/get-calendar.dto';
|
|
import { CreateEventDto } from './dto/create-event.dto';
|
|
import { CreateExceptionDto } from './dto/create-exception.dto';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { RolesGuard } from '../auth/roles.guard';
|
|
import { Roles } from '../auth/roles.decorator';
|
|
import { Role } from '../auth/role.enum';
|
|
import { CreateBookingDto } from './dto/create-booking.dto';
|
|
import { CancelBookingDto } from './dto/cancel-booking.dto';
|
|
|
|
@Controller('calendar')
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles(Role.Admin)
|
|
export class CalendarController {
|
|
constructor(private readonly calendarService: CalendarService) {}
|
|
|
|
@Get()
|
|
getCalendarEvents(@Query() getCalendarDto: GetCalendarDto) {
|
|
return this.calendarService.getEventsInRange(
|
|
getCalendarDto.startDate,
|
|
getCalendarDto.endDate,
|
|
);
|
|
}
|
|
|
|
// Standard CRUD endpoints for managing event entities
|
|
@Post('events')
|
|
createEvent(@Body() createEventDto: CreateEventDto) {
|
|
return this.calendarService.createEvent(createEventDto);
|
|
}
|
|
|
|
@Get('events/:id')
|
|
getEventById(@Param('id', ParseIntPipe) id: number) {
|
|
return this.calendarService.getEventById(id);
|
|
}
|
|
|
|
@Patch('events/:id')
|
|
updateEvent(
|
|
@Param('id', ParseIntPipe) id: number,
|
|
@Body() updateEventDto: CreateEventDto,
|
|
) {
|
|
return this.calendarService.updateEvent(id, updateEventDto);
|
|
}
|
|
|
|
@Delete('events/:id')
|
|
deleteEvent(@Param('id', ParseIntPipe) id: number) {
|
|
return this.calendarService.deleteEvent(id);
|
|
}
|
|
|
|
// Endpoint for creating exceptions to a recurring event
|
|
@Post('events/:id/exceptions')
|
|
createException(
|
|
@Param('id', ParseIntPipe) eventId: number,
|
|
@Body() createExceptionDto: CreateExceptionDto,
|
|
) {
|
|
return this.calendarService.createException(eventId, createExceptionDto);
|
|
}
|
|
|
|
// Create a booking for a specific event occurrence
|
|
@Post('events/:id/bookings')
|
|
createBooking(
|
|
@Param('id', ParseIntPipe) eventId: number,
|
|
@Body() createBookingDto: CreateBookingDto,
|
|
) {
|
|
return this.calendarService.createBooking(eventId, createBookingDto);
|
|
}
|
|
|
|
// Cancel a specific booking (soft delete)
|
|
@Patch('bookings/:bookingId/cancel')
|
|
cancelBooking(
|
|
@Param('bookingId', ParseIntPipe) bookingId: number,
|
|
@Body() cancelBookingDto: CancelBookingDto,
|
|
) {
|
|
return this.calendarService.cancelBooking(bookingId, cancelBookingDto);
|
|
}
|
|
}
|