31 lines
No EOL
936 B
JavaScript
31 lines
No EOL
936 B
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { Mongo } from 'meteor/mongo';
|
|
import { check } from 'meteor/check';
|
|
|
|
export const Measurements = new Mongo.Collection('measurements');
|
|
|
|
Measurements.allow({
|
|
insert: function(userId, doc){
|
|
// if use id exists, allow insert
|
|
return !!userId;
|
|
},
|
|
});
|
|
|
|
Meteor.methods({
|
|
async 'add.measurement' (measurementName, measurementUnits) {
|
|
check(measurementName, String);
|
|
check(measurementUnits, String);
|
|
|
|
if (!this.userId) {
|
|
throw new Meteor.Error('You are not allowed to add measurements. Make sure you are logged in with valid user credentials.');
|
|
}
|
|
|
|
return await Measurements.insertAsync({
|
|
measurementName: measurementName,
|
|
measurementUnits: measurementUnits,
|
|
addedBy: this.userId,
|
|
addedOn: new Date(),
|
|
measurementActive: true,
|
|
});
|
|
},
|
|
}); |