{"size": 655, "ext": "js", "max_stars_repo_path": "app/models/form/open-question.js", "max_stars_repo_name": "Matthijsy/amber-ui", "max_stars_repo_stars_event_min_datetime": "2019-05-21T07:40:04.000Z", "max_stars_repo_stars_event_max_datetime": "2019-05-21T07:40:04.000Z", "max_issues_repo_path": "app/models/form/open-question.js", "max_issues_repo_name": "Matthijsy/amber-ui", "max_issues_repo_issues_event_min_datetime": "2019-04-24T21:17:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T08:15:29.000Z", "max_forks_repo_path": "app/models/form/open-question.js", "max_forks_repo_name": "Matthijsy/amber-ui", "max_forks_repo_forks_event_min_datetime": "2019-07-25T02:42:34.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-09T14:06:48.000Z"}
{"max_stars_count": 1, "max_issues_count": 187, "max_forks_count": 4, "avg_line_length": 22.5862068966, "max_line_length": 68, "alphanum_fraction": 0.6351145038}
import Model, { hasMany, belongsTo, attr } from '@ember-data/model';

export default class OpenQuestion extends Model {
  @attr question;
  @attr fieldType;
  @attr position;
  @attr required;
  @attr('date') createdAt;
  @attr('date') updatedAt;

  // Relations
  @belongsTo('form/form') form;
  @hasMany('form/open-question-answer') answers;

  // Getters
  isOpenQuestion = true;

  get sumOfAnswers() {
    if (this.fieldType === 'number') {
      const answers = this.answers.filterBy('completed', true);
      return answers.mapBy('answer').reduce((a, b) => {
        return parseFloat(a) + parseFloat(b);
      }, 0);
    }

    return null;
  }
}
