Skip to content
Snippets Groups Projects
feature-api.js 1.97 KiB
Newer Older
import axios from 'axios';
import store from '../store'

const baseUrl = store.state.configuration.VUE_APP_DJANGO_API_BASE;

const featureAPI = {
  async getFeatureEvents(featureId) {
    const response = await axios.get(
      `${baseUrl}features/${featureId}/events/`
    );
    if (
      response.status === 200 &&
      response.data
    ) {
      return response.data;
    } else {
      return null;
    }
  },

  async getFeatureAttachments(featureId) {
    const response = await axios.get(
      `${baseUrl}features/${featureId}/attachments/`
    );
    if (
      response.status === 200 &&
      response.data
    ) {
      return response.data;
    } else {
      return null;
    }
  },

  async postComment({ featureId, comment }) {
Timothee P's avatar
Timothee P committed
    const response = await axios.post(
      `${baseUrl}features/${featureId}/comments/`, { comment }
    );
    if (
      response.data
    ) {
      return response;
    } else {
      return null;
    }
  },

  async postCommentAttachment({ featureId, file, fileName, commentId, title }) {
    let formdata = new FormData();
    formdata.append("file", file, fileName);
    formdata.append("title", title);
    const response = await axios.put(
      `${baseUrl}features/${featureId}/comments/${commentId}/upload-file/`, formdata
    );
    if (
      response.status === 200 &&
      response.data
    ) {
      return response;
    } else {
      return null;
    }

  async getFeatureLinks(featureId) {
    const response = await axios.get(
      `${baseUrl}features/${featureId}/feature-links/`
    );
    if (
      response.status === 200 &&
      response.data
    ) {
      return response.data;
    } else {
      return null;
    }
  },
Timothee P's avatar
Timothee P committed

  async getFeaturesBlob(url) {
    const response = await axios
      .get(url, { responseType: "blob" })
    if (
      response.status === 200 &&
      response.data
    ) {
      return response.data;
    } else {
      return null;
    }
  },
}

export default featureAPI;