mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 16:28:50 +00:00
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
|
|
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] + ".");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|