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 Locations = new Mongo.Collection('locations');
|
|
|
|
|
|
|
|
|
|
Locations.allow({
|
|
|
|
|
insert: function(userId, doc){
|
|
|
|
|
// if use id exists, allow insert
|
|
|
|
|
return !!userId;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Meteor.methods({
|
2022-08-15 18:07:39 -05:00
|
|
|
'add.location' (name) {
|
2022-08-05 16:55:56 -05:00
|
|
|
check(name, String);
|
|
|
|
|
|
|
|
|
|
if (!this.userId) {
|
|
|
|
|
throw new Meteor.Error('You are not allowed to add locations. Make sure you are logged in with valid user credentials.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Locations.insert({
|
|
|
|
|
locationName: name,
|
2022-08-15 18:07:39 -05:00
|
|
|
owner: this.userId,
|
2022-08-05 16:55:56 -05:00
|
|
|
});
|
|
|
|
|
},
|
2022-08-15 18:07:39 -05:00
|
|
|
'edit.location' (locationId, locationName) {
|
2022-08-05 16:55:56 -05:00
|
|
|
check(locationId, String);
|
|
|
|
|
check(locationName, String);
|
|
|
|
|
|
|
|
|
|
if (!this.userId) {
|
|
|
|
|
throw new Meteor.Error('You are not allowed to edit locations. Make sure you are logged in with valid user credentials.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Locations.update({ _id: locationId }, {
|
|
|
|
|
$set: {
|
|
|
|
|
locationName: locationName,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
'delete.location' (locationId) {
|
|
|
|
|
check(locationId, String);
|
|
|
|
|
|
|
|
|
|
if (!this.userId) {
|
|
|
|
|
throw new Meteor.Error('You are not allowed to delete locations. Make sure you are logged in with valid user credentials.');
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 11:18:18 -05:00
|
|
|
return Locations.remove({ _id: locationId });
|
2022-08-05 16:55:56 -05:00
|
|
|
},
|
|
|
|
|
});
|