Updaated Products to have multiple associated stores.

- Products will be updated on first start of server to make sure the store attribute is set as an Array of values.
- You can edit Products to add more associated stores
- Products will list all associated stores on the product table view
- Cut down method calls to single event trigger for adding / editing products info
This commit is contained in:
Brian McGonagill 2024-08-13 10:48:27 -05:00
parent a7a9c48e01
commit 3f6618d906
4 changed files with 56 additions and 96 deletions

View file

@ -1,6 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { SysConfig } from '../imports/api/systemConfig';
import { MenuItems } from '../imports/api/menuItems';
import { Products } from '../imports/api/products.js';
Meteor.startup(() => {
// code to run on server at startup
@ -22,7 +23,7 @@ Meteor.startup(() => {
// check if the isLInked item exists on menuitems, and if not, add it (data cleanup task)
let itemInfoNoLink = MenuItems.find({ isLinked: { $exists: false } }).fetch();
console.log("No Ites with isLinked not set: " + itemInfoNoLink.length);
// console.log("No Ites with isLinked not set: " + itemInfoNoLink.length);
if (itemInfoNoLink.length > 0) {
// console.log("found items with isLinked not set.");
// console.dir(itemInfoNoLink);
@ -36,7 +37,33 @@ Meteor.startup(() => {
}
} else {
// this will show if all items are found to have isLInked set.
// console.log("No itesm with isLinked not set.");
console.log("No itesm with isLinked not set.");
}
// update Products to be able to have multiple stores in the document
let prodInfo = Products.find({}).fetch();
let prodCount = prodInfo.length;
console.log("Updating Products to allow multiple store assocation for " + prodCount + " products.");
for (j = 0; j < prodCount; j++) {
if (typeof prodInfo[j].prodStore == 'object') {
// console.log(typeof prodInfo[j].prodStore);
// console.log("Is Array already");
} else {
let prodStoreArray = [];
// console.log("---- ---- ----");
// console.log(typeof prodInfo[j].prodStore);
// console.log("---- Is Not Array.");
let prodStore = prodInfo[j].prodStore;
prodStoreArray.push(prodStore);
// console.dir(prodStoreArray);
Products.update({ _id: prodInfo[j]._id }, {
$set: {
prodStore: prodStoreArray,
}
});
}
}
});