mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-26 15:58:50 +00:00
90 lines
No EOL
2.7 KiB
JavaScript
90 lines
No EOL
2.7 KiB
JavaScript
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({
|
|
async 'add.list' (listName, isShared) {
|
|
check(listName, String);
|
|
check(isShared, Boolean);
|
|
|
|
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 await Lists.insertAsync({
|
|
listName: listName,
|
|
listShared: isShared,
|
|
listOwner: this.userId,
|
|
listComplete: false,
|
|
});
|
|
},
|
|
async 'edit.list' (listId, listName, isShared) {
|
|
check(listId, String);
|
|
check(listName, String);
|
|
check(isShared, Boolean);
|
|
|
|
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 await Lists.updateAsync({ _id: listId }, {
|
|
$set: {
|
|
listName: listName,
|
|
listShared: isShared,
|
|
}
|
|
});
|
|
},
|
|
async '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.');
|
|
}
|
|
|
|
return await Lists.removeAsync({ _id: listId });
|
|
},
|
|
async 'mark.complete' (listId) {
|
|
check(listId, String);
|
|
|
|
if (!this.userId) {
|
|
throw new Meteor.Error('You are not allowed to mark lists complete. Make sure you are logged in with valid user credentials.');
|
|
}
|
|
|
|
return await Lists.updateAsync({ _id: listId }, {
|
|
$set: {
|
|
listComplete: true,
|
|
completedOn: new Date()
|
|
}
|
|
});
|
|
},
|
|
async 'mark.incomplete' (listId) {
|
|
check(listId, String);
|
|
|
|
if (!this.userId) {
|
|
throw new Meteor.Error('You are not allowed to restore completed lists. Make sure you are logged in with valid user credentials.');
|
|
}
|
|
|
|
return await Lists.updateAsync({ _id: listId }, {
|
|
$set: {
|
|
listComplete: false,
|
|
completedOn: new Date()
|
|
}
|
|
});
|
|
},
|
|
async 'clean.Lists' () {
|
|
if (!this.userId) {
|
|
throw new Meteor.Error('You are not allowed to clean up old lists. Make sure you are logged in with valid user credentials.');
|
|
}
|
|
|
|
return await Lists.removeAsync({ listComplete: true });
|
|
},
|
|
}); |