Added Task Mgmt, and framework for Recipes.

This commit is contained in:
Brian McGonagill 2022-09-05 09:39:54 -05:00
parent 3b9a54daf1
commit 947abfb76f
13 changed files with 430 additions and 1 deletions

View file

@ -0,0 +1,57 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const RecipeItems = new Mongo.Collection('recipeitems');
RecipeItems.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.recipeItem' (recipeId, recipeItemType, recipeItem) {
check(recipeId, String);
check(recipeItemType, String);
check(recipeItem, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add recipe items. Make sure you are logged in with valid user credentials.');
}
return RecipeItems.insert({
recipeId: recipeId,
recipeItemType: recipeItemType,
recipeItem: recipeItem,
});
},
'edit.recipeItem' (recipeItemId, recipeId, recipeItemType, recipeItem) {
check(recipeItemId, String);
check(recipeId, String);
check(recipeItemType, String);
check(recipeItem, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to edit recipe items. Make sure you are logged in with valid user credentials.');
}
return RecipeItems.update({ _id: recipeItemId }, {
$set: {
recipeId: recipeId,
recipeItemType: recipeItemType,
recipeItem: recipeItem,
}
});
},
'delete.recipeItem' (recipeItemId) {
check(recipeItemId, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete recipe items. Make sure you are logged in with valid user credentials.');
}
return RecipeItems.remove({ _id: recipeItemId });
}
});

53
imports/api/recipes.js Normal file
View file

@ -0,0 +1,53 @@
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({
'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 Recipes.insert({
recipeName: recipeName,
addedBy: this.userId,
addedOn: new Date(),
});
},
'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 Recipes.update({ _id: recipeId }, {
$set: {
recipeName: recipeName,
updatedOn: new Date(),
updatedBy: this.userId,
}
});
},
'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 Recipes.remove({ _id: recipeId });
}
});

93
imports/api/tasks.js Normal file
View file

@ -0,0 +1,93 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const TaskItems = new Mongo.Collection('taskitems');
TaskItems.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
'add.task' (taskName, assignedTo, taskDate) {
check(taskName, String);
check(assignedTo, String);
check(taskDate, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add tasks. Make sure you are logged in with valid user credentials.');
}
return TaskItems.insert({
taskName: taskName,
taskDate: taskDate,
assignedTo: assignedTo,
isComplete: false,
completedOn: null,
assignedOn: new Date(),
assignedBy: this.userId,
});
},
'edit.task' (taskId, taskName, assignedTo, taskDate) {
check(taskId, String);
check(taskName, String);
check(assignedTo, String);
check(taskDate, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to edit tasks. Make sure you are logged in with valid user credentials.');
}
return TaskItems.update({ _id: taskId }, {
$set: {
taskName: taskName,
taskDate: taskDate,
assignedTo: assignedTo,
changedOn: new Date(),
changedBy: this.userId,
}
});
},
'delete.task' (taskId) {
check(taskId, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to delete tasks. Make sure you are logged in with valid user credentials.');
}
return TaskItems.remove({ _id: taskId });
},
'markTask.complete' (taskId) {
check(taskId, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to mark tasks complete. Make sure you are logged in with valid user credentials.');
}
return TaskItems.update({ _id: taskId }, {
$set: {
isComplete: true,
completedOn: new Date(),
completedBy: this.userId,
}
});
},
'markTask.notComplete' (taskId) {
check(taskId, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to mark tasks not complete. Make sure you are logged in with valid user credentials.');
}
return TaskItems.update({ _id: taskId }, {
$set: {
isComplete: false,
markedUncomplteOn: new Date(),
markedUncompleteBy: this.userId,
}
});
},
});