src/controllers/requestController.js
/** Function to search in the trip requests table according to what the user is typing
   * @param {object} req the request sent to the server
   * @param {object} res the response returned
   * @param {object} keyword to be searched for
   * @returns {object} found data
   */
Function to search in the trip requests table according to what the user is typing
@param {object} req the request sent to the server
@param {object} res the response returned
@param {object} keyword to be searched for
@returns {object} found data
Function to search in the trip requests table according to what the user is typing @param { object } req the request sent to the server @param { object } res the response returned @param { object } keyword to be searched for @returns { object } found data
static async search(req, res) {
    const { keyword } = req.query;
    let response;
    try {
      const result = await RequestServices.search(keyword);
      if (result.length === 0) {
        response = new Response(res, 404, `Ooops. Nothing was found for ${keyword}`);
        return response.sendErrorMessage();
      }
      const data = [];
      result.forEach(obj => {
        const objData = {
          id: obj.id,
          first_nameorigin: obj.first_name,
          last_name: obj.last_name,
          origin: obj.origin,
          destination: obj.destination,
          travelDate: obj.travel_date,
          returnDate: obj.return_date,
          status: obj.status
        };
        data.push(objData);
      });
      response = new Response(res, 200, `The results for ${keyword}`, data);
      return response.sendSuccessResponse();
    } catch (error) {
      response = new Response(res, 500, `Internal Server Error: ${error}`);
      return response.sendErrorMessage();
    }
  }
static async search ( req , res ) { const { keyword } = req . query ; let response ; try { const result = await RequestServices . search ( keyword ) ; if ( result . length === 0 ) { response = new Response ( res , 404 , ` ${ keyword } ` ) ; return response . sendErrorMessage ( ) ; } const data = [ ] ; result . forEach ( obj => { const objData = { id : obj . id , first_nameorigin : obj . first_name , last_name : obj . last_name , origin : obj . origin , destination : obj . destination , travelDate : obj . travel_date , returnDate : obj . return_date , status : obj . status } ; data . push ( objData ) ; } ) ; response = new Response ( res , 200 , ` ${ keyword } ` , data ) ; return response . sendSuccessResponse ( ) ; } catch ( error ) { response = new Response ( res , 500 , ` ${ error } ` ) ; return response . sendErrorMessage ( ) ; } }
Function to search in the trip requests table according to what the user is typing
 @param {object} req the request sent to the server
 @param {object} res the response returned
 @param {object} keyword to be searched for
 @returns {object} found data
Function to search in the trip requests table according to what the user is typing @param { object } req the request sent to the server @param { object } res the response returned @param { object } keyword to be searched for @returns { object } found data