mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
My big initial commit to this repo and project.
This commit is contained in:
parent
750811a81f
commit
8636f8cf9b
2433 changed files with 199488 additions and 1042 deletions
57
imports/api/lists.js
Normal file
57
imports/api/lists.js
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
|
||||
export const Lists = new Mongo.Collection('lists');
|
||||
|
||||
Lists.allow({
|
||||
insert: function(userId, doc){
|
||||
// if use id exists, allow insert
|
||||
return !!userId;
|
||||
},
|
||||
});
|
||||
|
||||
Meteor.methods({
|
||||
'add.list' (listName) {
|
||||
check(listName, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to add lists. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return Lists.insert({
|
||||
listName: listName,
|
||||
listOwner: this.userId;
|
||||
});
|
||||
},
|
||||
'edit.list' (listId, listName) {
|
||||
check(listId, String);
|
||||
check(listName, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to edit lists. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return Lists.update({ _id: listId }, {
|
||||
$set: {
|
||||
listName: listName,
|
||||
}
|
||||
});
|
||||
},
|
||||
'delete.list' (listId) {
|
||||
check(listId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to delete lists. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
let listInfo = Lists.findOne({ _id: listId });
|
||||
let myId = this.userId;
|
||||
if (myId == listInfo.owner) {
|
||||
return Lists.remove({ _id: listId });
|
||||
} else {
|
||||
console.log("User not allowed to delete this list. Not the owner!");
|
||||
return("Not Allowed!");
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue