Backend/Microservices/UserService/server/src/Helpers/server.js
/**
    * Method to execute the Handlers.
    * @param handlerData: The request object after parsing it.
    */
Method to execute the Handlers.
@param handlerData: The request object after parsing it.
Method to execute the Handlers . @param handlerData : The request object after parsing it .
function execHandlers(handlerData) {
      const apiKey = handlerData[constants.API_TOKEN_KEY];
      const api = new Api(apiKey);
      printer.printHighlightedLog(handlerData.postData);
      printer.printHighlightedLog(handlerData.path);
      delete handlerData[constants.API_TOKEN_KEY];
      if (handlerData.method === constants.HTTP_OPTIONS) {
         sendResponse({}, constants.HTTP_SUCCESS);
      } else if (handlerData.path !== 'ping') {
         api.validateToken().then(() => {
            delete handlerData[constants.API_TOKEN_KEY];
            let promise = chosenHandler(handlerData);
            promise.then((responseObject) => {
               const requestKey = generator.generateRandomToken(16);
               api.logAPIStatus(requestKey, handlerData.path, responseObject[0]);
               responseObject[1][constants.API_REQUEST_KEY] = requestKey;
               sendResponse(responseObject[1], responseObject[0]);
            }).catch(err => {
               const requestKey = generator.generateRandomToken(16);
               api.logAPIStatus(requestKey, handlerData.path, err[0]);
               err[1][constants.API_REQUEST_KEY] = requestKey;
               sendResponse(err[1], err[0]);
            });
         }).catch(err => {
            printer.printError(err);
            const response = responseGenerator.generateErrorResponse(constants.ERROR_MESSAGE, constants.ERROR_LEVEL_4);
            const requestKey = generator.generateRandomToken(16);
            api.logAPIStatus(requestKey, handlerData.path, err[0]);
            err[1][constants.API_REQUEST_KEY] = requestKey;
            sendResponse(response[1], response[0]);
         });
      } else {
         sendResponse(constants.WELCOME_MESSAGE, constants.HTTP_SUCCESS);
      }
   }
function execHandlers ( handlerData ) { const apiKey = handlerData [ constants . API_TOKEN_KEY ] ; const api = new Api ( apiKey ) ; printer . printHighlightedLog ( handlerData . postData ) ; printer . printHighlightedLog ( handlerData . path ) ; delete handlerData [ constants . API_TOKEN_KEY ] ; if ( handlerData . method === constants . HTTP_OPTIONS ) { sendResponse ( { } , constants . HTTP_SUCCESS ) ; } else if ( handlerData . path !== 'ping' ) { api . validateToken ( ) . then ( ( ) => { delete handlerData [ constants . API_TOKEN_KEY ] ; let promise = chosenHandler ( handlerData ) ; promise . then ( ( responseObject ) => { const requestKey = generator . generateRandomToken ( 16 ) ; api . logAPIStatus ( requestKey , handlerData . path , responseObject [ 0 ] ) ; responseObject [ 1 ] [ constants . API_REQUEST_KEY ] = requestKey ; sendResponse ( responseObject [ 1 ] , responseObject [ 0 ] ) ; } ) . catch ( err => { const requestKey = generator . generateRandomToken ( 16 ) ; api . logAPIStatus ( requestKey , handlerData . path , err [ 0 ] ) ; err [ 1 ] [ constants . API_REQUEST_KEY ] = requestKey ; sendResponse ( err [ 1 ] , err [ 0 ] ) ; } ) ; } ) . catch ( err => { printer . printError ( err ) ; const response = responseGenerator . generateErrorResponse ( constants . ERROR_MESSAGE , constants . ERROR_LEVEL_4 ) ; const requestKey = generator . generateRandomToken ( 16 ) ; api . logAPIStatus ( requestKey , handlerData . path , err [ 0 ] ) ; err [ 1 ] [ constants . API_REQUEST_KEY ] = requestKey ; sendResponse ( response [ 1 ] , response [ 0 ] ) ; } ) ; } else { sendResponse ( constants . WELCOME_MESSAGE , constants . HTTP_SUCCESS ) ; } }
Method to execute the Handlers.
Method to execute the Handlers .