mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 08:18:50 +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
61
imports/api/location.js
Normal file
61
imports/api/location.js
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
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({
|
||||
'add.location' (name, type) {
|
||||
check(name, String);
|
||||
check(type, 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,
|
||||
locationType: type,
|
||||
owner: this.userid,
|
||||
});
|
||||
},
|
||||
'edit.location' (locationId, locationName, locationType) {
|
||||
check(locationId, String);
|
||||
check(locationName, String);
|
||||
check(locationType, 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,
|
||||
locationType: locationType,
|
||||
}
|
||||
});
|
||||
},
|
||||
'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.');
|
||||
}
|
||||
|
||||
let locationInfo = Locations.findOne({ _id: locationId });
|
||||
let myId = this.userId;
|
||||
if (myId == locationInfo.owner) {
|
||||
return Locations.remove({ _id: locationId });
|
||||
} else {
|
||||
console.log("User not allowed to delete this location. Not the owner!");
|
||||
return("Not Allowed!");
|
||||
}
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue