text: import Ember from 'ember';
  
  export default Ember.Route.extend({
    bookmarkQuestions: Ember.inject.service(),
  
    model(params) {
      return Ember.RSVP.hash({
        questions: this.store.findRecord('question', params.question_id),
        answers: this.store.findAll('answer')
      });
    },
    actions: {
      deleteQuestion(question) {
        var answer_deletions = question.get('answers').map(function(answer) {
          return answer.destroyRecord();
        });
        Ember.RSVP.all(answer_deletions).then(function() {
          return question.destroyRecord();
        });
        this.transitionTo('index');
      },
  
      updateQuestion(question, params) {
        Object.keys(params).forEach(function(key) {
          if(params[key] !== undefined) {
            question.set(key, params[key]);
          }
        });
        question.save();
        this.transitionTo('question');
      },
  
      saveAnswer(params) {
        var newAnswer = this.store.createRecord('answer', params);
        var question = params.question;
        question.get('answers').addObject(newAnswer);
        newAnswer.save().then(function() {
          return question.save();
        });
        this.transitionTo('question');
      },
  
      updateAnswer(answer, params) {
        Object.keys(params).forEach(function(key) {
          if(params[key] !== undefined) {
            answer.set(key, params[key]);
          }
        });
        answer.save();
        this.transitionTo('question');
      },
  
      deleteAnswer(answer) {
        var question = answer.get('question');
        answer.destroyRecord().then(function() {
          question.save();
        });
        this.transitionTo('post');
      },
  
      upvote(answerId) {
        this.store.findRecord('answer', answerId).then(function(answer) {
          answer.incrementProperty('rating');
          answer.save();
        });
        this.refresh();
      },
  
      downvote(answerId) {
        this.store.findRecord('answer', answerId).then(function(answer) {
          answer.decrementProperty('rating');
          answer.save();
        });
        this.refresh();
      }
    }
  });
  