Skip to content
Snippets Groups Projects
project-api.js 2.17 KiB
Newer Older
import axios from '@/axios-client.js';
  async getProject( baseUrl, projectSlug ) {
    const response = await axios.get(
      `${baseUrl}projects/${projectSlug}/`
    );
    if (
      response.status === 200 &&
      response.data
    ) {
      return response.data;
    } else {
      return null;
    }
  },

  async getProjectSubscription({ baseUrl, projectSlug }) {
    const response = await axios.get(
      `${baseUrl}projects/${projectSlug}/subscription/`
    );
    if (
      response.status === 200 &&
      response.data
    ) {
      return response.data;
    } else {
      return null;
    }
  },

  async subscribeProject({ baseUrl, projectSlug, suscribe }) {
    const response = await axios.put(
      `${baseUrl}projects/${projectSlug}/subscription/`,
      { is_suscriber: suscribe }
    );
    if (
      response.status === 200 &&
      response.data
    ) {
      return response.data;
    } else {
      return null;
    }
  },
  async getProjects({ baseUrl, filters, page, projectSlug, myaccount }) {
Timothee P's avatar
Timothee P committed
    let url = `${baseUrl}projects/`;
    if (projectSlug) url += `${projectSlug}/`;
    url += `?page=${page}`;
    if (myaccount) {
      url += '&myaccount=true';
Timothee P's avatar
Timothee P committed
    }
    try {
      if (Object.values(filters).some(el => el && el.length > 0)) {
        for (const filter in filters) {
          if (filters[filter]) {
Timothee P's avatar
Timothee P committed
            url = url.concat('', `&${filter}=${filters[filter]}`);
Timothee P's avatar
Timothee P committed
      const response = await axios.get(url);
      if (response.status === 200 && response.data) {
        return response.data;
      }
    } catch (error) {
      console.error(error);
      throw error;
    }
Florent Lavelle's avatar
Florent Lavelle committed
  },
  async getProjectTypes( baseUrl ) {
    const response = await axios.get(
      `${baseUrl}project-types/`
    );
    if (
      response.status === 200 &&
      response.data
    ) {
      return response.data;
    } else {
      return null;
    }
  },

  async deleteProject(baseUrl, projectSlug) {
Timothee P's avatar
Timothee P committed
    const response = await axios.delete(
      `${baseUrl}projects/${projectSlug}/`
Timothee P's avatar
Timothee P committed
    );
    if ( response.status === 204 ) {
      return 'success';
    } else {
      return null;
    }
  },
Timothee P's avatar
Timothee P committed
};

export default projectAPI;