40 lines
No EOL
1.2 KiB
JavaScript
40 lines
No EOL
1.2 KiB
JavaScript
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({
|
|
async 'add.location' (locName, locDesc, locTypeName, locTypeId, isChild, parentName, parentId) {
|
|
check(locName, String);
|
|
check(locDesc, String);
|
|
check(locTypeName, String);
|
|
check(locTypeId, String);
|
|
check(isChild, Boolean);
|
|
check(parentName, String);
|
|
check(parentId, 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 await Locations.insertAsync({
|
|
locationName: locName,
|
|
locationDesc: locDesc,
|
|
locationTypeName: locTypeName,
|
|
locationTypeId: locTypeId,
|
|
isChild: isChild,
|
|
parentName: parentName,
|
|
parentId: parentId,
|
|
addedOn: new Date(),
|
|
addedBy: this.userId,
|
|
});
|
|
},
|
|
}); |