@Post('/bookings/create') async createBooking( @Body() createBookingDto: createBookingDto ): Promise<BookingResponseDto> { const { email } = createBookingDto; // Checks if the email exists or not, if it doesn’t exists then we will create an account, else we will use the existing user to create a booking let user = await this.userRepository.findByEmail(email); if (!user){ const password = Utilities.generatePassword(16); // We use a random password here to create the user on auth0 const { auth0Response } = await this.createUserOnAuth0( email, password, ); this.logger.debug(auth0Response, 'Created Auth0 User'); let userData: CreateUserDto = { email, auth0UserId: auth0Response['_id'], }; // Creates and links the auth0 user with our DB user = await this.userRepository.addUser(userData); } const booking = { userId: user.id, transactionId: createBookingDto.transaction.id, // Assuming the payment was done before this API call in a different service showId: createBookingDto.show.id, theaterId: createBookingDto.theater.id, seatNumbers: createBookingDto.seats } // Creates a booking const bookingObject = await this.bookingRepository.bookTicket(booking) return new BookingResponseDto(bookingObject) }