src/controllers/requestController.js
/**
   * @description This methods helps users edit requests that are still pending
   * @param  {object} req - The request object
   * @param  {object} res - The response object
   * @returns  {object} The response object
   */
@description This methods helps users edit requests that are still pending
@param  {object} req - The request object
@param  {object} res - The response object
@returns  {object} The response object
@description This methods helps users edit requests that are still pending @param { object } req - The request object @param { object } res - The response object @returns { object } The response object
static async editRequest(req, res) {
    const { requestData } = req;
    const requestId = req.params.id;
    const userEmail = req.userData.email;
    const request = await Request.findOne({
      where: {
        id: requestId
      }
    });
    const user = await User.findOne({
      where: {
        email: userEmail
      }
    });
    if (!request) {
      return res.status(404).json({
        status: 404,
        error: 'Request not found',
      });
    }
    if (request.user_id === user.id) {
      if (request.status === 'Pending') {
        const updated = await RequestRepository.update({ id: requestId }, requestData);
        if (!updated) {
          return res.status(500).json({
            status: 500,
            error: 'Internal server error'
          });
        }
        const notification = {
          eventType: 'edited_request',
          requestId
        };
        eventEmitter.emit('notification', notification);
        return res.status(200).json({
          status: 200,
          message: 'Request edited successfully'
        });
      }
      return res.status(412).json({
        status: 412,
        error: 'Precondition failed',
      });
    }
    return res.status(401).json({
      status: 401,
      error: 'Unauthorized access',
    });
  }
static async editRequest ( req , res ) { const { requestData } = req ; const requestId = req . params . id ; const userEmail = req . userData . email ; const request = await Request . findOne ( { where : { id : requestId } } ) ; const user = await User . findOne ( { where : { email : userEmail } } ) ; if ( ! request ) { return res . status ( 404 ) . json ( { status : 404 , error : 'Request not found' , } ) ; } if ( request . user_id === user . id ) { if ( request . status === 'Pending' ) { const updated = await RequestRepository . update ( { id : requestId } , requestData ) ; if ( ! updated ) { return res . status ( 500 ) . json ( { status : 500 , error : 'Internal server error' } ) ; } const notification = { eventType : 'edited_request' , requestId } ; eventEmitter . emit ( 'notification' , notification ) ; return res . status ( 200 ) . json ( { status : 200 , message : 'Request edited successfully' } ) ; } return res . status ( 412 ) . json ( { status : 412 , error : 'Precondition failed' , } ) ; } return res . status ( 401 ) . json ( { status : 401 , error : 'Unauthorized access' , } ) ; }
@description This methods helps users edit requests that are still pending
 @param  {object} req - The request object
 @param  {object} res - The response object
 @returns  {object} The response object
@description This methods helps users edit requests that are still pending @param { object } req - The request object @param { object } res - The response object @returns { object } The response object