2022-08-05 16:55:56 -05:00
|
|
|
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({
|
2022-08-23 13:41:21 -05:00
|
|
|
'add.list' (listName, isShared) {
|
2022-08-05 16:55:56 -05:00
|
|
|
check(listName, String);
|
2022-08-23 13:41:21 -05:00
|
|
|
check(isShared, Boolean);
|
2022-08-05 16:55:56 -05:00
|
|
|
|
|
|
|
|
if (!this.userId) {
|
|
|
|
|
throw new Meteor.Error('You are not allowed to add lists. Make sure you are logged in with valid user credentials.');
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-21 07:28:59 -05:00
|
|
|
return Lists.insertAsync({
|
2022-08-05 16:55:56 -05:00
|
|
|
listName: listName,
|
2022-08-23 13:41:21 -05:00
|
|
|
listShared: isShared,
|
2022-08-16 16:46:14 -05:00
|
|
|
listOwner: this.userId,
|
|
|
|
|
listComplete: false,
|
2022-08-05 16:55:56 -05:00
|
|
|
});
|
|
|
|
|
},
|
2022-08-23 13:41:21 -05:00
|
|
|
'edit.list' (listId, listName, isShared) {
|
2022-08-05 16:55:56 -05:00
|
|
|
check(listId, String);
|
|
|
|
|
check(listName, String);
|
2022-08-23 13:41:21 -05:00
|
|
|
check(isShared, Boolean);
|
2022-08-05 16:55:56 -05:00
|
|
|
|
|
|
|
|
if (!this.userId) {
|
|
|
|
|
throw new Meteor.Error('You are not allowed to edit lists. Make sure you are logged in with valid user credentials.');
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-21 07:28:59 -05:00
|
|
|
return Lists.updateAsync({ _id: listId }, {
|
2022-08-05 16:55:56 -05:00
|
|
|
$set: {
|
|
|
|
|
listName: listName,
|
2022-08-23 13:41:21 -05:00
|
|
|
listShared: isShared,
|
2022-08-05 16:55:56 -05:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
'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.');
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-21 07:28:59 -05:00
|
|
|
return Lists.removeAsync({ _id: listId });
|
2022-08-16 16:46:14 -05:00
|
|
|
},
|
|
|
|
|
'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.');
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-21 07:28:59 -05:00
|
|
|
return Lists.updateAsync({ _id: listId }, {
|
2022-08-23 13:41:21 -05:00
|
|
|
$set: {
|
|
|
|
|
listComplete: true,
|
|
|
|
|
completedOn: new Date()
|
|
|
|
|
}
|
2025-05-26 16:22:58 -05:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
'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.');
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-21 07:28:59 -05:00
|
|
|
return Lists.updateAsync({ _id: listId }, {
|
2025-05-26 16:22:58 -05:00
|
|
|
$set: {
|
|
|
|
|
listComplete: false,
|
|
|
|
|
completedOn: new Date()
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-07-30 16:32:06 -05:00
|
|
|
},
|
|
|
|
|
'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.');
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-21 07:28:59 -05:00
|
|
|
return Lists.removeAsync({ listComplete: true });
|
2024-07-30 16:32:06 -05:00
|
|
|
},
|
2022-08-05 16:55:56 -05:00
|
|
|
});
|