32 lines
No EOL
925 B
JavaScript
32 lines
No EOL
925 B
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { Mongo } from 'meteor/mongo';
|
|
import { check } from 'meteor/check';
|
|
|
|
export const MeasureLogEntry = new Mongo.Collection('measureLogEntry');
|
|
|
|
MeasureLogEntry.allow({
|
|
insert: function(userId, doc){
|
|
// if use id exists, allow insert
|
|
return !!userId;
|
|
},
|
|
});
|
|
|
|
Meteor.methods({
|
|
async 'add.measureLog' (measureName, measure, units) {
|
|
check(measureName, String);
|
|
check(measure, Number);
|
|
check(units, String);
|
|
|
|
if (!this.userId) {
|
|
throw new Meteor.Error('You are not allowed to add measurement log entries. Make sure you are logged in with valid user credentials.');
|
|
}
|
|
|
|
return MeasureLogEntry.insertAsync({
|
|
measureName: measureName,
|
|
measure: measure,
|
|
measureUnits: units,
|
|
addedBy: this.userId,
|
|
addedOn: new Date(),
|
|
});
|
|
},
|
|
}); |