open-health/imports/api/workoutLog.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2026-02-03 16:03:34 -06:00
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const WorkoutLog = new Mongo.Collection('workoutLog');
WorkoutLog.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
async 'add.log' (routineId, exerciseName, exerciseType, measure, measureUnits) {
check(routineId, String);
check(exerciseName, String);
check(exerciseType, String);
check(measure, String);
check(measureUnits, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to add routines. Make sure you are logged in with valid user credentials.');
}
return await WorkoutLog.insertAsync({
routineId: routineId,
exerciseName: exerciseName,
exerciseType: exerciseType,
measure: measure,
measureUnits: measureUnits,
addedBy: this.userId,
addedOn: new Date(),
exerciseActive: true,
});
},
});