mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
Added List and Menu clean up.
This commit is contained in:
parent
2f3f82477a
commit
e60c32894c
7 changed files with 211 additions and 9 deletions
|
|
@ -1,6 +1,9 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
import { MenuItems } from './menuItems';
|
||||
import moment from 'moment';
|
||||
import { mark } from '@babel/runtime/regenerator';
|
||||
|
||||
export const Menus = new Mongo.Collection('menus');
|
||||
|
||||
|
|
@ -73,5 +76,50 @@ Meteor.methods({
|
|||
menuComplete: false,
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
'clean.Menus' () {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to clean up old Menus. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
let removeMenuIds = [];
|
||||
|
||||
|
||||
// let's find all the menus with menu items that are past their date.
|
||||
let menuList = Menus.find({ menuComplete: false }).fetch();
|
||||
for (i=0; i < menuList.length; i++) {
|
||||
let removeMenu = true;
|
||||
let items = MenuItems.find({ menuId: menuList[i]._id }).fetch();
|
||||
for (j=0; j < items.length; j++) {
|
||||
let srvDate = moment(items[j].serveDateActual);
|
||||
let today = moment();
|
||||
let expired = moment(today).isAfter(srvDate);
|
||||
// console.log("Expired: " + expired);
|
||||
if (expired != true) {
|
||||
removeMenu = false;
|
||||
}
|
||||
if (j == items.length - 1) {
|
||||
if (removeMenu == true) {
|
||||
removeMenuIds.push(menuList[i]._id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
for (l = 0; l < removeMenuIds.length; l++) {
|
||||
Menus.remove({ _id: removeMenuIds[l] });
|
||||
}
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue