server/src/Entity/customer.js
/**
    * Method to create the customer.
    * @param {String} usedReferralCode
    */
Method to create the customer.
Method to create the customer .
createCustomer(usedReferralCode) {
      return new Promise((resolve, reject) => {
         this._ownReferalCode = generator.generateRandomToken(6);
         database.runSp(constants.SP_CREATE_CUSTOMER, [this._firstName, this._lastName, this._email,
            this._password, this._phone, this._gender, this._ownReferalCode,
            validators.validateUndefined(usedReferralCode) ? usedReferralCode : false
         ]).then(_resultSet => {
            const result = _resultSet[0][0];
            let response = {};
            if (validators.validateUndefined(result) && result.id > 0) {
               this._id = result.id;
               let customerData = {};
               customerData[constants.CUSTOMER_FIRST_NAME] = this._firstName;
               customerData[constants.CUSTOMER_LAST_NAME] = this._lastName;
               customerData[constants.CUSTOMER_EMAIL] = this._email;
               customerData[constants.CUSTOMER_ID] = this._id;
               response[constants.JW_TOKEN] = tokenGenerator.getToken(customerData);
               response[constants.CUSTOMER_ID] = this._id;
               resolve(response);
            } else {
               resolve({id: -1});
            }
         }).catch(err => {
            printer.printError(err);
            reject(err);
         });
      });
   }
createCustomer ( usedReferralCode ) { return new Promise ( ( resolve , reject ) => { this . _ownReferalCode = generator . generateRandomToken ( 6 ) ; database . runSp ( constants . SP_CREATE_CUSTOMER , [ this . _firstName , this . _lastName , this . _email , this . _password , this . _phone , this . _gender , this . _ownReferalCode , validators . validateUndefined ( usedReferralCode ) ? usedReferralCode : false ] ) . then ( _resultSet => { const result = _resultSet [ 0 ] [ 0 ] ; let response = { } ; if ( validators . validateUndefined ( result ) && result . id > 0 ) { this . _id = result . id ; let customerData = { } ; customerData [ constants . CUSTOMER_FIRST_NAME ] = this . _firstName ; customerData [ constants . CUSTOMER_LAST_NAME ] = this . _lastName ; customerData [ constants . CUSTOMER_EMAIL ] = this . _email ; customerData [ constants . CUSTOMER_ID ] = this . _id ; response [ constants . JW_TOKEN ] = tokenGenerator . getToken ( customerData ) ; response [ constants . CUSTOMER_ID ] = this . _id ; resolve ( response ) ; } else { resolve ( { id : - 1 } ) ; } } ) . catch ( err => { printer . printError ( err ) ; reject ( err ) ; } ) ; } ) ; }
Method to create the customer.
Method to create the customer .