|
| 1 | +import { |
| 2 | + Body, |
| 3 | + Controller, |
| 4 | + Delete, |
| 5 | + Get, |
| 6 | + Param, |
| 7 | + Post, |
| 8 | + Put, |
| 9 | + UseGuards, |
| 10 | +} from '@nestjs/common'; |
| 11 | +import { ApiBody, ApiTags } from '@nestjs/swagger'; |
| 12 | + |
| 13 | +import { CalendarService } from './calendar.service'; |
| 14 | +import { CalendarDto } from './calendar.dto'; |
| 15 | +import { Roles } from 'src/auth/authroization/roles.decorator'; |
| 16 | +import { RolesGuard } from 'src/auth/authroization/roles.guard'; |
| 17 | +import { UserType } from 'src/popo/user/user.meta'; |
| 18 | +import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard'; |
| 19 | +import * as moment from 'moment'; |
| 20 | + |
| 21 | +@ApiTags('Calendar') |
| 22 | +@Controller('calendar') |
| 23 | +export class CalendarController { |
| 24 | + constructor(private readonly calendarService: CalendarService) {} |
| 25 | + |
| 26 | + @Post() |
| 27 | + @Roles(UserType.admin, UserType.association) |
| 28 | + @UseGuards(JwtAuthGuard, RolesGuard) |
| 29 | + @ApiBody({ type: CalendarDto }) |
| 30 | + createCalendar(@Body() dto: CalendarDto) { |
| 31 | + return this.calendarService.save(dto); |
| 32 | + } |
| 33 | + |
| 34 | + @Get() |
| 35 | + getAllCalendars() { |
| 36 | + return this.calendarService.findAll(); |
| 37 | + } |
| 38 | + |
| 39 | + @Get('get-next-event') |
| 40 | + async getNextEvent() { |
| 41 | + const today = moment().format('YYYY-MM-DD'); |
| 42 | + const events = await this.calendarService.findEventAfter(today); |
| 43 | + return events[0]; |
| 44 | + } |
| 45 | + |
| 46 | + @Get(':id') |
| 47 | + getCalendarByUuid(@Param('id') id: number) { |
| 48 | + return this.calendarService.findById(id); |
| 49 | + } |
| 50 | + |
| 51 | + @Put(':id') |
| 52 | + @Roles(UserType.admin, UserType.association) |
| 53 | + @UseGuards(JwtAuthGuard, RolesGuard) |
| 54 | + @ApiBody({ type: CalendarDto }) |
| 55 | + updateCalendar(@Param('id') id: number, @Body() dto: CalendarDto) { |
| 56 | + return this.calendarService.update(id, dto); |
| 57 | + } |
| 58 | + |
| 59 | + @Delete(':id') |
| 60 | + @Roles(UserType.admin, UserType.association) |
| 61 | + @UseGuards(JwtAuthGuard, RolesGuard) |
| 62 | + deleteCalendar(@Param('id') id: number) { |
| 63 | + return this.calendarService.delete(id); |
| 64 | + } |
| 65 | +} |
0 commit comments