const { differenceInYears, parseISO } = require('date-fns');
module.exports = {
afterFindMany(event) {
event.result.forEach(profile => {
if (profile.DateOfBirth) {
profile.Age = calculateAge(profile.DateOfBirth);
}
});
},
};
function calculateAge(dateOfBirth) {
const today = new Date();
const birthDate = parseISO(dateOfBirth);
return differenceInYears(today, birthDate);
}
This code fixed my issue. But can i schedule this to run once every week without running on afterFindMany to reduce load on each fetch and just load only once every week