mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
dev work on menu to prod link
This commit is contained in:
parent
01ae220674
commit
9abb198e82
7 changed files with 163 additions and 3 deletions
44
imports/api/menuProdLinks.js
Normal file
44
imports/api/menuProdLinks.js
Normal 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] + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue