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, }); }, });