Adding endpoint to update recurring reservations
This commit is contained in:
parent
360acfb63b
commit
feb3c4b8d0
2 changed files with 53 additions and 3 deletions
|
|
@ -7,6 +7,7 @@ import {
|
|||
Inject,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common'
|
||||
|
|
@ -52,6 +53,31 @@ export class CreateRecurringReservationRequest {
|
|||
opponents?: CreateRecurringReservationOpponent[]
|
||||
}
|
||||
|
||||
export class UpdateRecurringReservationRequest {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
ownerId?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsEnum(DayOfWeek)
|
||||
dayOfWeek?: number
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@Matches(/[012][0-9]:[0-5][0-9]/)
|
||||
timeStart?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@Matches(/[012][0-9]:[0-5][0-9]/)
|
||||
timeEnd?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested()
|
||||
opponents?: CreateRecurringReservationOpponent[]
|
||||
}
|
||||
|
||||
@Controller('recurring-reservations')
|
||||
@UseInterceptors(ClassSerializerInterceptor)
|
||||
export class RecurringReservationsController {
|
||||
|
|
@ -69,18 +95,29 @@ export class RecurringReservationsController {
|
|||
}
|
||||
|
||||
@Get(':id')
|
||||
getReservationById(@Param('id') id: string) {
|
||||
getRecurringReservationById(@Param('id') id: string) {
|
||||
return this.recurringReservationsService.getById(id)
|
||||
}
|
||||
|
||||
@Post()
|
||||
async createReservation(@Body() req: CreateRecurringReservationRequest) {
|
||||
async createRecurringReservation(
|
||||
@Body() req: CreateRecurringReservationRequest,
|
||||
) {
|
||||
await this.recurringReservationsService.create(req)
|
||||
return 'Recurring reservation created'
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
async updateRecurringReservation(
|
||||
@Param('id') id: string,
|
||||
@Body() req: UpdateRecurringReservationRequest,
|
||||
) {
|
||||
await this.recurringReservationsService.update(id, req)
|
||||
return 'Recurring reservation updated'
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
async deleteReservationById(@Param('id') id: string) {
|
||||
async deleteRecurringReservationById(@Param('id') id: string) {
|
||||
await this.recurringReservationsService.deleteById(id)
|
||||
return 'Recurring reservation deleted'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,6 +58,19 @@ export class RecurringReservationsService {
|
|||
return this.reservationsService.create(reservation)
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
updateRequest: {
|
||||
ownerId?: string
|
||||
dayOfWeek?: DayOfWeek
|
||||
timeStart?: string
|
||||
timeEnd?: string
|
||||
opponents?: { id: string; name: string }[]
|
||||
},
|
||||
) {
|
||||
await this.recurringReservationsRepository.update({ id }, updateRequest)
|
||||
}
|
||||
|
||||
async deleteById(id: string) {
|
||||
await this.recurringReservationsRepository.delete({ id })
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue