dev work on menu to prod link

This commit is contained in:
Brian McGonagill 2024-07-28 19:42:23 -05:00
parent 01ae220674
commit 9abb198e82
7 changed files with 163 additions and 3 deletions

View file

@ -0,0 +1,44 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
import { Products } from './products';
export const MenuProdLinks = new Mongo.Collection('menuProdLinks');
MenuProdLinks.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.menuProdLinks' (menuItemId, prodNameArray) {
check(menuItemId, String);
check(prodNameArray, [String]);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add menu and product links. Make sure you are logged in with valid user credentials.');
}
let productObj = {};
let prodNameLength = prodNameArray.length;
for (i=0; i<prodNameLength; i++) {
let product = Products.findOne({ prodName: prodNameArray[i] });
if (typeof product != 'undefined' && product != null && product != "") {
let prodId = product._id;
MenuProdLinks.insert({
menuItemId: menuItemId,
prodName: prodNameArray[i],
prodId: prodId,
dateCreated: Date(),
createdBy: this.userId
});
} else {
console.log(" ERROR - unable to find a matching product by name: " + prodName[i] + ".");
}
}
}
});