DeepCode00

Insert multientity

Sep 2nd, 2021 (edited)
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     @Post()
  2.     @UseGuards(JwtAuthGuard)
  3.     @ApiBearerAuth()
  4.     @UsePipes(new ValidationPipe({ transform: true }))
  5.     @ApiBody({ type: TicketDto })
  6.     @ApiCreatedResponse({description: 'Ticket created'})
  7.     @ApiOperation({ summary: 'Insert ticket' })
  8.     @ApiResponse({ status: 201, description: 'The ticket has been successfully inserted.'})
  9.     @ApiResponse({ status: 403, description: 'Forbidden.' })
  10.     @ApiUnauthorizedResponse({description: 'Not authenticated or not admin on organization'})
  11.     async insert(
  12.         @Body() entity: TicketPaymentsDto,
  13.         @Request() req,
  14.     ): Promise<TicketEntity | InternalServerErrorException | UnauthorizedException | undefined> {
  15.         const ticket: TicketEntity | InternalServerErrorException | UnauthorizedException | undefined =
  16.             await this.entitiesService.insert(entity, req);
  17.         if (ticket instanceof TicketEntity) {
  18.             entity.payments[0].ticketId = ticket.id;
  19.             const payments = await this.paymentsService.insert(entity.payments[0]);
  20.             if (payments) {
  21.                 return await this.entitiesService.findOne(ticket.id, req);
  22.             } else {
  23.                 return new InternalServerErrorException('Insert payment failed');
  24.             }
  25.         } else {
  26.             return new InternalServerErrorException('Insert failed');
  27.         }
  28.     }
Add Comment
Please, Sign In to add comment