I try to make a cronjob which checks last updates of files.
But when a new Object is to be pushed in the array of file information the array is complete overwritten. Could someone give a hint, please? Tried also with "push(...value)"
const cron = require('node-cron');
let openCalculationFiles = [{}];
module.exports = {
cronjobCalculationUsage: () => {
cron.schedule('30,0 * * * * *', async() => {
....
});
},
upsertOpenCalculation: (projectId) => {
console.log(openCalculationFiles);
const openCalculation = openCalculationFiles.filter(element => element.projectId = projectId)[0];
if (openCalculation) { // This works
openCalculation.lastUpdate = new Date().getTime();
} else {
const newOpenCalculation = {
"projectId": projectId,
"lastUpdate": new Date().getTime()
};
openCalculationFiles.push(newOpenCalculation); // This makes complete new Array, last one wins
}
console.log(openCalculationFiles);
}