Backend/Microservices/OrderInventoryService/server/src/Entity/order.js
/**
    * Method to create a order.
    * @param orderDate: The date of the order.
    * @param addressId: The address of the user where it is to be delivered.
    * @param couponCode: The coupon code entered by the user.
    * @param baseAmount: The base amount.
    * @param discount: The discount amount.
    * @param replaceOrderId: If replace order, then id, else NaN.
    * @param productsArray: The json array containing the sku and quantity of the order.
    * @param transactionId: The payment transaction id.
    * @param jwToken: The token of the user placing the order.
    * @returns {Promise<Array>}:
    */
Method to create a order.
@param orderDate: The date of the order.
@param addressId: The address of the user where it is to be delivered.
@param couponCode: The coupon code entered by the user.
@param baseAmount: The base amount.
@param discount: The discount amount.
@param replaceOrderId: If replace order, then id, else NaN.
@param productsArray: The json array containing the sku and quantity of the order.
@param transactionId: The payment transaction id.
@param jwToken: The token of the user placing the order.
@returns {Promise}.
Method to create a order . @param orderDate : The date of the order . @param addressId : The address of the user where it is to be delivered . @param couponCode : The coupon code entered by the user . @param baseAmount : The base amount . @param discount : The discount amount . @param replaceOrderId : If replace order then id else NaN . @param productsArray : The json array containing the sku and quantity of the order . @param transactionId : The payment transaction id . @param jwToken : The token of the user placing the order . @returns { Promise } .
createOrder(orderDate, addressId, couponCode, baseAmount, discount, replaceOrderId, productsArray, transactionId, jwToken) {
      return new Promise(async (resolve, reject) => {
         try {
            const userData = await utils.validateUserToken(jwToken);
            if (validators.validateUndefined(userData) && userData[constants.ID] > 0 &&
               utils.checkWhetherRoleExists(userData[constants.ROLES], constants.ROLE_CUSTOMER_ID)) {
               this._flycastOrderId = utils.generateOrderId(orderDate, addressId, userData[constants.ID], baseAmount);
               database.runSp(constants.SP_CREATE_ORDER, [this._flycastOrderId, orderDate, userData[constants.ID],
                  addressId, baseAmount, discount, replaceOrderId, JSON.stringify(productsArray)]).then(_resultSet => {
                  const result = _resultSet[0][0];
                  if (validators.validateUndefined(result) && result[constants.ORDER_ID] > 0) {
                     this._orderId = result[constants.ORDER_ID];
                     resolve([constants.RESPONSE_SUCESS_LEVEL_1, result]);
                     this._requestPaymentCapture(transactionId, baseAmount, couponCode, jwToken);
                  } else {
                     resolve([constants.RESPONSE_SUCESS_LEVEL_1, result]);
                  }
               }).catch(err => {
                  printer.printError(err);
                  reject([constants.ERROR_LEVEL_3, constants.ERROR_MESSAGE]);
               });
            } else {
               reject([constants.ERROR_LEVEL_4, constants.FORBIDDEN_MESSAGE]);
            }
         } catch (e) {
            printer.printError(e);
            reject([constants.ERROR_LEVEL_3, constants.ERROR_MESSAGE]);
         }
      });
   }
createOrder ( orderDate , addressId , couponCode , baseAmount , discount , replaceOrderId , productsArray , transactionId , jwToken ) { return new Promise ( async ( resolve , reject ) => { try { const userData = await utils . validateUserToken ( jwToken ) ; if ( validators . validateUndefined ( userData ) && userData [ constants . ID ] > 0 && utils . checkWhetherRoleExists ( userData [ constants . ROLES ] , constants . ROLE_CUSTOMER_ID ) ) { this . _flycastOrderId = utils . generateOrderId ( orderDate , addressId , userData [ constants . ID ] , baseAmount ) ; database . runSp ( constants . SP_CREATE_ORDER , [ this . _flycastOrderId , orderDate , userData [ constants . ID ] , addressId , baseAmount , discount , replaceOrderId , JSON . stringify ( productsArray ) ] ) . then ( _resultSet => { const result = _resultSet [ 0 ] [ 0 ] ; if ( validators . validateUndefined ( result ) && result [ constants . ORDER_ID ] > 0 ) { this . _orderId = result [ constants . ORDER_ID ] ; resolve ( [ constants . RESPONSE_SUCESS_LEVEL_1 , result ] ) ; this . _requestPaymentCapture ( transactionId , baseAmount , couponCode , jwToken ) ; } else { resolve ( [ constants . RESPONSE_SUCESS_LEVEL_1 , result ] ) ; } } ) . catch ( err => { printer . printError ( err ) ; reject ( [ constants . ERROR_LEVEL_3 , constants . ERROR_MESSAGE ] ) ; } ) ; } else { reject ( [ constants . ERROR_LEVEL_4 , constants . FORBIDDEN_MESSAGE ] ) ; } } catch ( e ) { printer . printError ( e ) ; reject ( [ constants . ERROR_LEVEL_3 , constants . ERROR_MESSAGE ] ) ; } } ) ; }
Method to create a order.
Method to create a order .