server/src/Entity/booking.js
/**
    * Method to create a Subscription's service booking.
    * It books a service from an active subscription.
    * @param subscriptionId: The Subscription that the user is buying.
    * @param vendorId: The vendor id.
    * @param addressId: The address id of the customer.
    * @param bookingTime: The booking date.
    * @param bookingEndTime: the end time of the booking.
    * @param bookingDate: The booking time.
    * @param bookingEndDate
    * @param breedId
    * @param remarks
    * @param recurringBookings: The array containing the recurring dates and time.
    * @returns {Promise<Number>}: The booking id.
    */
Method to create a Subscription's service booking.
It books a service from an active subscription.
@param subscriptionId: The Subscription that the user is buying.
@param vendorId: The vendor id.
@param addressId: The address id of the customer.
@param bookingTime: The booking date.
@param bookingEndTime: the end time of the booking.
@param bookingDate: The booking time.
@param bookingEndDate
@param breedId
@param remarks
@param recurringBookings: The array containing the recurring dates and time.
@returns {Promise}: The booking id.
Method to create a Subscription ' s service booking . It books a service from an active subscription . @param subscriptionId : The Subscription that the user is buying . @param vendorId : The vendor id . @param addressId : The address id of the customer . @param bookingTime : The booking date . @param bookingEndTime : the end time of the booking . @param bookingDate : The booking time . @param bookingEndDate @param breedId @param remarks @param recurringBookings : The array containing the recurring dates and time . @returns { Promise } : The booking id .
createSubscriptionServiceBooking(subscriptionId, vendorId, addressId, bookingTime, bookingEndTime, bookingDate, bookingEndDate,
                                    breedId, remarks, recurringBookings) {
      return new Promise((resolve, reject) => {
         database.runSp(constants.SP_HANDLE_BOOKING, [constants.BOOKING_TYPE_SUBSCRIPTION_SERVICE, this._customerId,
            subscriptionId, this._serviceId, vendorId, 0, bookingDate,
            validators.validateUndefined(bookingEndTime) ? bookingEndDate : bookingDate,
            bookingTime, bookingEndTime, addressId,
            breedId,
            validators.validateString(remarks) ? remarks : "",
            0, 0]).then(_resultSet => {
            const result = _resultSet[0][0];
            if (validators.validateUndefined(result) && result.id > 0) {
               this._bookingId = result.id;
               if (validators.validateUndefined(recurringBookings)) {
                  let recurringDates = [];
                  let recurringTimes = [];
                  recurringBookings.forEach(oneBooking => {
                     recurringDates.push(oneBooking[constants.BOOKING_DATE]);
                     recurringTimes.push(oneBooking[constants.BOOKING_TIME]);
                  });
                  database.runSp(constants.SP_STORE_RECURRING_BOOKING, [recurringDates.join(","),
                     recurringTimes.join(","), this._bookingId]).then(async _resultSet => {
                     const result = _resultSet[0][0];
                     await this._notifyVendor(vendorId);
                     resolve(result);
                  }).catch(err => {
                     printer.printError(err);
                     reject(err);
                  });
               } else {
                  resolve(result);
               }
            } else {
               resolve({id: -1});
            }
         }).catch(err => {
            printer.printError(err);
            reject(err);
         });
      });
   }
createSubscriptionServiceBooking ( subscriptionId , vendorId , addressId , bookingTime , bookingEndTime , bookingDate , bookingEndDate , breedId , remarks , recurringBookings ) { return new Promise ( ( resolve , reject ) => { database . runSp ( constants . SP_HANDLE_BOOKING , [ constants . BOOKING_TYPE_SUBSCRIPTION_SERVICE , this . _customerId , subscriptionId , this . _serviceId , vendorId , 0 , bookingDate , validators . validateUndefined ( bookingEndTime ) ? bookingEndDate : bookingDate , bookingTime , bookingEndTime , addressId , breedId , validators . validateString ( remarks ) ? remarks : "" , 0 , 0 ] ) . then ( _resultSet => { const result = _resultSet [ 0 ] [ 0 ] ; if ( validators . validateUndefined ( result ) && result . id > 0 ) { this . _bookingId = result . id ; if ( validators . validateUndefined ( recurringBookings ) ) { let recurringDates = [ ] ; let recurringTimes = [ ] ; recurringBookings . forEach ( oneBooking => { recurringDates . push ( oneBooking [ constants . BOOKING_DATE ] ) ; recurringTimes . push ( oneBooking [ constants . BOOKING_TIME ] ) ; } ) ; database . runSp ( constants . SP_STORE_RECURRING_BOOKING , [ recurringDates . join ( "," ) , recurringTimes . join ( "," ) , this . _bookingId ] ) . then ( async _resultSet => { const result = _resultSet [ 0 ] [ 0 ] ; await this . _notifyVendor ( vendorId ) ; resolve ( result ) ; } ) . catch ( err => { printer . printError ( err ) ; reject ( err ) ; } ) ; } else { resolve ( result ) ; } } else { resolve ( { id : - 1 } ) ; } } ) . catch ( err => { printer . printError ( err ) ; reject ( err ) ; } ) ; } ) ; }
Method to create a Subscription's service booking.
Method to create a Subscription ' s service booking .