Initial commit
This commit is contained in:
parent
9ed5089508
commit
78e0e82449
16 changed files with 317 additions and 15 deletions
57
imports/api/workouts.js
Normal file
57
imports/api/workouts.js
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
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,
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue