{"size": 1192, "ext": "js", "max_stars_repo_path": "app/adapters/userpreference.js", "max_stars_repo_name": "whasselbring/explorviz-frontend", "max_stars_repo_stars_event_min_datetime": "2018-12-07T16:59:01.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-28T03:05:22.000Z", "max_issues_repo_path": "app/adapters/userpreference.js", "max_issues_repo_name": "whasselbring/explorviz-frontend", "max_issues_repo_issues_event_min_datetime": "2018-01-04T14:45:05.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-17T14:33:52.000Z", "max_forks_repo_path": "app/adapters/userpreference.js", "max_forks_repo_name": "ExplorViz/explorviz-ui-frontend", "max_forks_repo_forks_event_min_datetime": "2018-05-17T23:42:16.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-14T09:39:37.000Z"}
{"max_stars_count": 4, "max_issues_count": 131, "max_forks_count": 5, "avg_line_length": 24.3265306122, "max_line_length": 75, "alphanum_fraction": 0.6602348993}
import JSONAPIAdapter from 'ember-data/adapters/json-api';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import ENV from 'explorviz-frontend/config/environment';

export default JSONAPIAdapter.extend(DataAdapterMixin, {

  host: ENV.APP.API_ROOT,

  init() {

    this.set('headers', {
      "Accept": "application/vnd.api+json"
    });

  },

  // @Override
  urlForQuery(query) {
    let id = query.userId;
    // delete s.t. query parameter won't be attached (i.e. ?userId=id)
    delete query.userId;
    const baseUrl = this.buildURL();
    return `${baseUrl}/v1/preferences?filter[user]=${id}`;
  },

  // @Override
  // Overrides URL for model.save()
  urlForCreateRecord() {
    const baseUrl = this.buildURL();
    return `${baseUrl}/v1/preferences`;
  },

  urlForUpdateRecord(id) {
    const baseUrl = this.buildURL();
    return `${baseUrl}/v1/preferences/${id}`;
  },

  urlForDeleteRecord(id) {
    const baseUrl = this.buildURL();
    return `${baseUrl}/v1/preferences/${id}`;
  },

  authorize(xhr) {
    let { access_token } = this.get('session.data.authenticated');
    xhr.setRequestHeader('Authorization', `Bearer ${access_token}`);
  }

});
