summaryrefslogtreecommitdiff
path: root/app/services/commands/create-workout-command.js
blob: 7ade156bf4456ebcaac7ec3d1414031fb566b91e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import * as events from '../events';

export default class CreateWorkoutCommand {
  constructor(eventAggregator, api) {
    this.eventAggregator = eventAggregator;
    this.api = api;
  }

  subscribeTo(eventAggregator) {
    eventAggregator.subscribe(events.CREATE_WORKOUT, this);
  }

  notify(event) {
    const body = {
      workout: {
        body_weight: event.body_weight,
        exercise_sets_attributes: event.sets,
        routine_id: event.routine_id,
      }
    };
    this.api.post('/workouts', body, this.onResponse.bind(this));
  }

  onResponse(json) {
    console.log("CREATED");
    console.log(json);
  }
}