47 lines
No EOL
1.7 KiB
JavaScript
47 lines
No EOL
1.7 KiB
JavaScript
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.exerciseToLog' (routineId, exerciseName, exerciseType, exerciseMeasure, exerciseUnitMeasure, exerciseMeasure2, exerciseUnitMeasure2, exerciseMeasure3, exerciseUnitMeasure3, exerciseInstruction) {
|
|
check(routineId, String);
|
|
check(exerciseName, String);
|
|
check(exerciseType, String);
|
|
check(exerciseMeasure, String);
|
|
check(exerciseUnitMeasure, String);
|
|
check(exerciseMeasure2, String);
|
|
check(exerciseUnitMeasure2, String);
|
|
check(exerciseMeasure3, String);
|
|
check(exerciseUnitMeasure3, String);
|
|
check(exerciseInstruction, 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,
|
|
exerciseMeasure: exerciseMeasure,
|
|
exerciseUnitMeasure: exerciseUnitMeasure,
|
|
exerciseMeasure2: exerciseMeasure2,
|
|
exerciseUnitMeasure2: exerciseUnitMeasure2,
|
|
exerciseMeasure3: exerciseMeasure3,
|
|
exerciseUnitMeasure3: exerciseUnitMeasure3,
|
|
exerciseInstruction: exerciseInstruction,
|
|
addedBy: this.userId,
|
|
addedOn: new Date(),
|
|
exerciseActive: true,
|
|
});
|
|
},
|
|
}); |