Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

87
Views
Take a return on a javascript async function

I am trying to get a response of my checkNewActivities, Here you have the function calling:

checkNewActivities(area.userId, action, async (err, result) => {
                      if(!err) {
                        console.log(result);
                      } else {
                        console.log("Fail on checkNewActivities");
                      }
                    });

and here you have the function inside:

const checkNewActivities = (userID, action) => {
    User.findById(userID, async (error, user) => {
        if (!error) {
            // Call the EPITECH API with user.intranetToken
            const response = await axios.get(
                `https://intra.epitech.eu/${user.intranetToken}/planning/load/?format=json`
            );
            const codeEvent = action.backup.lastCode;
            const result = response.data.filter(
                (element) =>
                    element.semester == action.additionalInfo.semester && parseInt(element.codeevent.substring(6, 12)) > (codeEvent ? codeEvent : 0)
            );

            if (result.length > 0){
                Actions.findByIdAndUpdate(action._id, {
                    "backup.lastCode": parseInt(result[result.length - 1].codeevent.substring(6, 12))
                    },
                    function (err, actionModified) {
                    console.log(err, actionModified)
                })
            }
            console.log("THIS IS RESULT:",result);
            return result
        }
    });
};

I will really want to take the return to process it out of the function.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!