Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | import { Controller, Get, Post, Body, Param, Query, Req, UseGuards } from '@nestjs/common'; import { ApiTags, ApiOperation } from '@nestjs/swagger'; import { CalendarService } from './calendar.service'; import { AvailabilityEngine } from './availability.engine'; import { BookingEngine } from './booking-engine.service'; import { ConflictDetectionService } from './conflict-detection.service'; import { WorkingCalendarService } from './working-calendar.service'; @ApiTags('Calendar Platform') @Controller('api/v1/calendar') export class CalendarController { constructor( private readonly calendarSvc: CalendarService, private readonly availabilityEngine: AvailabilityEngine, private readonly bookingEngine: BookingEngine, private readonly conflictSvc: ConflictDetectionService, private readonly workingCalendarSvc: WorkingCalendarService ) {} @Post('calendars') @ApiOperation({ summary: 'Create new calendar definition' }) async createCalendar(@Req() req: any, @Body() body: any) { const tenantId = req.headers['x-tenant-id'] || 'default-tenant'; return this.calendarSvc.createCalendar(tenantId, body); } @Get('calendars/:id') @ApiOperation({ summary: 'Get calendar definition by ID' }) async getCalendar(@Req() req: any, @Param('id') id: string) { const tenantId = req.headers['x-tenant-id'] || 'default-tenant'; return this.calendarSvc.getCalendarById(tenantId, id); } @Post('events') @ApiOperation({ summary: 'Create a calendar event' }) async createEvent(@Req() req: any, @Body() body: any) { const tenantId = req.headers['x-tenant-id'] || 'default-tenant'; return this.calendarSvc.createEvent(tenantId, body); } @Post('events/:id/invite') @ApiOperation({ summary: 'Invite participant to event' }) async invite(@Req() req: any, @Param('id') eventId: string, @Body() body: any) { const tenantId = req.headers['x-tenant-id'] || 'default-tenant'; return this.calendarSvc.inviteParticipant(tenantId, eventId, body); } @Post('events/:id/respond') @ApiOperation({ summary: 'Respond to event invitation' }) async respond( @Req() req: any, @Param('id') eventId: string, @Body() body: { participantId: string; responseStatus: string; comment?: string } ) { const tenantId = req.headers['x-tenant-id'] || 'default-tenant'; return this.calendarSvc.respondToInvite(tenantId, eventId, body.participantId, body.responseStatus, body.comment); } @Post('availability/query') @ApiOperation({ summary: 'Query available time slots' }) async queryAvailability( @Req() req: any, @Body() body: { participantIds: string[]; resourceIds: string[]; startAt: string; endAt: string; durationMinutes: number; bufferMinutes?: number } ) { const tenantId = req.headers['x-tenant-id'] || 'default-tenant'; return this.availabilityEngine.findAvailableSlots( tenantId, body.participantIds, body.resourceIds, new Date(body.startAt), new Date(body.endAt), body.durationMinutes, body.bufferMinutes || 0 ); } @Post('conflicts/check') @ApiOperation({ summary: 'Check scheduling conflicts' }) async checkConflicts( @Req() req: any, @Body() body: { participantIds: string[]; resourceIds: string[]; startAt: string; endAt: string; allowDoubleBooking?: boolean } ) { const tenantId = req.headers['x-tenant-id'] || 'default-tenant'; return this.conflictSvc.checkConflicts( tenantId, body.participantIds, body.resourceIds, new Date(body.startAt), new Date(body.endAt), body.allowDoubleBooking || false ); } @Post('bookings') @ApiOperation({ summary: 'Create new booking / appointment' }) async createBooking(@Req() req: any, @Body() body: any) { const tenantId = req.headers['x-tenant-id'] || 'default-tenant'; return this.bookingEngine.createBooking(tenantId, { ...body, startAt: new Date(body.startAt), endAt: new Date(body.endAt) }); } @Post('bookings/holds') @ApiOperation({ summary: 'Request temporary slot hold' }) async createHold( @Req() req: any, @Body() body: { resourceId: string; startAt: string; endAt: string; userId: string; holdDurationMinutes?: number } ) { const tenantId = req.headers['x-tenant-id'] || 'default-tenant'; return this.bookingEngine.createHold( tenantId, body.resourceId, new Date(body.startAt), new Date(body.endAt), body.userId, body.holdDurationMinutes || 15 ); } @Post('working-hours/sla-minutes') @ApiOperation({ summary: 'Calculate elapsed working SLA minutes' }) async calculateSlaMinutes( @Req() req: any, @Body() body: { startAt: string; endAt: string } ) { const tenantId = req.headers['x-tenant-id'] || 'default-tenant'; return this.workingCalendarSvc.calculateWorkingMinutes( tenantId, new Date(body.startAt), new Date(body.endAt) ); } } |