open-health/imports/api/logEntry.js

50 lines
No EOL
1.6 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const LogEntry = new Mongo.Collection('logEntry');
LogEntry.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
async 'add.logEntry' (routineId, logId, exerciseName, measName1, measure1, measUnit1, measName2, measure2, measUnit2, measName3, measure3, measUnit3) {
check(routineId, String);
check(logId, String);
check(exerciseName, String);
check(measName1, String);
check(measure1, Number);
check(measUnit1, String);
check(measName2, String);
check(measure2, Number);
check(measUnit2, String);
check(measName3, String);
check(measure3, Number);
check(measUnit3, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add log entries. Make sure you are logged in with valid user credentials.');
}
return await LogEntry.insertAsync({
routineId: routineId,
logId: logId,
exerciseName: exerciseName,
measName1: measName1,
measure1: measure1,
measUnit1: measUnit1,
measName2: measName2,
measrue2: measure2,
measUnit2: measUnit2,
measName3: measName3,
measure3: measure3,
measUnit3: measUnit3,
addedBy: this.userId,
addedOn: new Date()
});
},
});