Aded Task cleanup by number of weeks or months

This commit is contained in:
Brian McGonagill 2024-08-01 11:56:04 -05:00
parent e60c32894c
commit 98bcbcd256
6 changed files with 93 additions and 23 deletions

View file

@ -94,7 +94,6 @@ Meteor.methods({
let srvDate = moment(items[j].serveDateActual);
let today = moment();
let expired = moment(today).isAfter(srvDate);
// console.log("Expired: " + expired);
if (expired != true) {
removeMenu = false;
}
@ -108,16 +107,12 @@ Meteor.methods({
// next let's add the ids of any menus that are marked complete
let markedComplete = Menus.find({ menuComplete: true }).fetch();
// console.log("---- ---- ----");
// console.dir(markedComplete);
for (k = 0; k < markedComplete.length; k++) {
let menuId = markedComplete[k]._id;
removeMenuIds.push(menuId);
}
// console.log(" ----- Need to remove Menus: ");
console.dir(removeMenuIds);
// finally we'll cycle through the ids and remove the items we collected up.
for (l = 0; l < removeMenuIds.length; l++) {
Menus.remove({ _id: removeMenuIds[l] });
}

View file

@ -1,6 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
import moment from 'moment';
export const TaskItems = new Mongo.Collection('taskitems');
@ -139,4 +140,40 @@ Meteor.methods({
}
});
},
'clean.Tasks' (timeFrame) {
check(timeFrame, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to clean up old Tasks. Make sure you are logged in with valid user credentials.');
}
let d = new Date();
let upToDate = "";
switch(timeFrame) {
case "1-week":
console.log("1 Week");
upToDate = 7 * 24 * 60 * 60 * 1000;
break;
case "2-weeks":
console.log("2 Week");
upToDate = 14 * 24 * 60 * 60 * 1000;
break;
case '1-month':
console.log("1 month");
upToDate = 30 * 24 * 60 * 60 * 1000;
break;
case '3-months':
console.log("3 months");
upToDate = 90 * 24 * 60 * 60 * 1000;
break;
case 'all':
console.log("all");
upToDate = 1 * 24 * 60 * 60 * 1000;
break;
default:
break;
}
return TaskItems.remove({ actualDate: { $lt: new Date((new Date()) - upToDate )}});
}
});