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.