{"size": 1687, "ext": "js", "max_stars_repo_path": "src/app/services/competency/competency.js", "max_stars_repo_name": "ebiwd/competency-mapper", "max_stars_repo_stars_event_min_datetime": "2020-07-20T08:43:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-20T08:43:48.000Z", "max_issues_repo_path": "src/app/services/competency/competency.js", "max_issues_repo_name": "ebiwd/competency-mapper", "max_issues_repo_issues_event_min_datetime": "2019-06-12T15:46:53.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T10:02:26.000Z", "max_forks_repo_path": "src/app/services/competency/competency.js", "max_forks_repo_name": "ebiwd/competency-mapper", "max_forks_repo_forks_event_min_datetime": "2019-03-08T11:04:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-03-22T13:39:43.000Z"}
{"max_stars_count": 1, "max_issues_count": 8, "max_forks_count": 2, "avg_line_length": 22.4933333333, "max_line_length": 69, "alphanum_fraction": 0.6662714878}
import HttpService from '../http/http';
import Body from './body';

export const apiUrl = process.env.REACT_APP_API_URL;

class CompetencyService {
  static instance;
  http = new HttpService();

  constructor() {
    if (CompetencyService.instance) {
      return this.instance;
    }

    CompetencyService.instance = this;
  }

  async getFramework(framework) {
    const response = await this.http.get(
      `${apiUrl}/api/v1/framework/${framework}?_format=json`
    );
    return response.data;
  }

  async getAllFrameworks() {
    const response = await this.http.get(
      `${apiUrl}/api/v1/framework/?_format=json`
    );
    return response.data;
  }

  async getAllFrameworksDetails() {
    const response = await this.http.get(`${apiUrl}/api/frameworks`);
    return response.data;
  }

  async createAttribute(options) {
    const response = await this.http.post(
      `${apiUrl}/node?_format=hal_json`,
      Body.createAttribute(options)
    );

    return response.data;
  }

  async createCompetency(options) {
    const response = await this.http.post(
      `${apiUrl}/node?_format=hal_json`,
      Body.createCompetency(options)
    );

    return response.data;
  }

  async patchCompetency(competencyId, key, value) {
    const response = await this.http.patch(
      `${apiUrl}/node/${competencyId}?_format=hal_json`,
      Body.mutateCompetency(key, value)
    );

    return response.data;
  }

  async patchAttribute(attributeId, key, value) {
    const response = await this.http.patch(
      `${apiUrl}/node/${attributeId}?_format=hal_json`,
      Body.mutateAttribute(key, value)
    );

    return response.data;
  }
}

export default CompetencyService;
