open-assets/imports/api/locations.js

40 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2026-01-24 13:49:38 -06: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({
2026-01-27 12:42:20 -06:00
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);
2026-01-24 13:49:38 -06:00
2026-01-27 12:42:20 -06:00
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,
});
},
2026-01-24 13:49:38 -06:00
});