open-health/imports/api/workouts.js
2026-02-03 16:03:34 -06:00

57 lines
No EOL
1.7 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const Workouts = new Mongo.Collection('workouts');
Workouts.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
async 'add.workoutRoutine' (routineName) {
check(routineName, 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 Workouts.insertAsync({
routineName: routineName,
addedBy: this.userId,
addedOn: new Date(),
routineActive: true,
});
},
async 'edit.workoutRoutine' (routineId, routineName) {
check(routineId, String);
check(routineName, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to edit routines. Make sure you are logged in with valid user credentials.');
}
return await Workouts.updateAsync({ _id: routineId }, {
$set: {
routineName: routineName,
dateModified: new Date(),
}
});
},
async 'deactivate.workoutRoutine' (routineId) {
check(routineId, String);
if (!this.userId) {
throw new Meteor.Error('You are not allowed to deactivate routines. Make sure you are logged in with valid user credentials.');
}
return await Workouts.updateAsync({ _id: routineId }, {
$set: {
routineActive: false,
}
});
}
});