mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-26 15:58:50 +00:00
53 lines
No EOL
1.5 KiB
JavaScript
53 lines
No EOL
1.5 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { Mongo } from 'meteor/mongo';
|
|
import { check } from 'meteor/check';
|
|
|
|
export const Recipes = new Mongo.Collection('recipes');
|
|
|
|
Recipes.allow({
|
|
insert: function(userId, doc){
|
|
// if use id exists, allow insert
|
|
return !!userId;
|
|
},
|
|
});
|
|
|
|
Meteor.methods({
|
|
async 'add.recipe' (recipeName) {
|
|
check(recipeName, String);
|
|
|
|
if (!this.userId) {
|
|
throw new Meteor.Error('You are not allowed to add recipes. Make sure you are logged in with valid user credentials.');
|
|
}
|
|
|
|
return await Recipes.insertAsync({
|
|
recipeName: recipeName,
|
|
addedBy: this.userId,
|
|
addedOn: new Date(),
|
|
});
|
|
},
|
|
async 'edit.recipe' (recipeId, recipeName) {
|
|
check(recipeId, String);
|
|
check(recipeName, String);
|
|
|
|
if (!this.userId) {
|
|
throw new Meteor.Error('You are not allowed to add recipes. Make sure you are logged in with valid user credentials.');
|
|
}
|
|
|
|
return await Recipes.updateAsync({ _id: recipeId }, {
|
|
$set: {
|
|
recipeName: recipeName,
|
|
updatedOn: new Date(),
|
|
updatedBy: this.userId,
|
|
}
|
|
});
|
|
},
|
|
async 'delete.recipe' (recipeId) {
|
|
check(recipeId, String);
|
|
|
|
if (!this.userId) {
|
|
throw new Meteor.Error('You are not allowed to delete recipes. Make sure you are logged in with valid user credentials.');
|
|
}
|
|
|
|
return await Recipes.removeAsync({ _id: recipeId });
|
|
}
|
|
}); |