Backend/Microservices/UserService/server/src/Entity/authentication.js
/**
    * Method to request and send OTP to a number.
    * @param extraData: The extra data that needs to be stored with the OTP.
    * @returns {Promise<Array>}
    */
Method to request and send OTP to a number.
@param extraData: The extra data that needs to be stored with the OTP.
@returns {Promise}
Method to request and send OTP to a number . @param extraData : The extra data that needs to be stored with the OTP . @returns { Promise }
createAndSendOTP(extraData) {
      return new Promise((resolve, reject) => {
         try {
            const otp = generator.generateOTP();
            const validity = generator.generateAheadTime(1);
            const otpMessage = constants.OTP_MESSAGE + otp;
            database.runSp(constants.SP_VALIDATE_OR_CREATE_OTP, [this._phone, otp, validity, 0,
               validators.validateString(extraData) ? extraData : false
            ]).then(async _resultSet => {
               const result = _resultSet[0][0].id;
               if (result > 0) {
                  await notificationManager.sendSMS(otpMessage, this._phone);
                  resolve([constants.RESPONSE_SUCESS_LEVEL_1, {"id": 1}]);
               } else {
                  resolve([constants.RESPONSE_SUCESS_LEVEL_1, {id: -1}]);
               }
            }).catch(err => {
               printer.printError(err);
               reject([constants.ERROR_LEVEL_3, constants.ERROR_MESSAGE]);
            });
         } catch (e) {
            printer.printError(e);
            reject([constants.ERROR_LEVEL_3, constants.ERROR_MESSAGE]);
         }
      });
   }
createAndSendOTP ( extraData ) { return new Promise ( ( resolve , reject ) => { try { const otp = generator . generateOTP ( ) ; const validity = generator . generateAheadTime ( 1 ) ; const otpMessage = constants . OTP_MESSAGE + otp ; database . runSp ( constants . SP_VALIDATE_OR_CREATE_OTP , [ this . _phone , otp , validity , 0 , validators . validateString ( extraData ) ? extraData : false ] ) . then ( async _resultSet => { const result = _resultSet [ 0 ] [ 0 ] . id ; if ( result > 0 ) { await notificationManager . sendSMS ( otpMessage , this . _phone ) ; resolve ( [ constants . RESPONSE_SUCESS_LEVEL_1 , { "id" : 1 } ] ) ; } else { resolve ( [ constants . RESPONSE_SUCESS_LEVEL_1 , { id : - 1 } ] ) ; } } ) . catch ( err => { printer . printError ( err ) ; reject ( [ constants . ERROR_LEVEL_3 , constants . ERROR_MESSAGE ] ) ; } ) ; } catch ( e ) { printer . printError ( e ) ; reject ( [ constants . ERROR_LEVEL_3 , constants . ERROR_MESSAGE ] ) ; } } ) ; }
Method to request and send OTP to a number.
Method to request and send OTP to a number .