Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/api/endpoints/apiActions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AxiosRequestConfig } from 'axios';
import { customInstance } from '../../../mock/mutator/customClient';
import { API_CONFIG } from '../../config';
import { useCookies } from 'react-cookie'


type SecondParameter<T extends (...args: any) => any> = Parameters<T>[1];
Expand All @@ -9,12 +10,13 @@ export const createPostRequest = <T = any, D = any>(endpoint: string, contentTyp
return (data?: D, options?: SecondParameter<typeof customInstance>) => {
return customInstance<T>(
{
url: API_CONFIG.BASE_URL + endpoint,
url: endpoint,
method: "POST",
data: data,
headers: {
"Content-Type": contentType,
},
withCredentials: true
},
options,
)
Expand All @@ -24,10 +26,11 @@ export const createPostRequest = <T = any, D = any>(endpoint: string, contentTyp
export const createGetRequest = <T = any, P = any>(endpoint: string, contentType?: string) => {
return (params?: P, options?: SecondParameter<typeof customInstance>, signal?: AbortSignal) => {
const config: AxiosRequestConfig = {
url: API_CONFIG.BASE_URL + endpoint,
url: endpoint,
method: "GET",
params,
signal,
withCredentials: true
}

if (contentType) {
Expand All @@ -36,7 +39,9 @@ export const createGetRequest = <T = any, P = any>(endpoint: string, contentType
"Content-Type": contentType,
}
}

return customInstance<T>(config, options)

return customInstance<T>(config, options).then(response => {
return response;
});
}
}
16 changes: 14 additions & 2 deletions src/api/endpoints/apiService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createPostRequest } from "./apiActions";
import React from "react";
import { createPostRequest, createGetRequest } from "./apiActions";
import { API_CONFIG } from "../../config";
import { GlobalDataContext } from "../../contexts/DataContext";

export interface LoginRequest {
username: string
Expand All @@ -16,4 +18,14 @@ export interface RegisterRequest {
}

export const login = createPostRequest<any, LoginRequest>(API_CONFIG.REAL_API.SIGNIN, "application/x-www-form-urlencoded")
export const register = createPostRequest<any, RegisterRequest>(API_CONFIG.REAL_API.NEWUSER_ILX, "application/x-www-form-urlencoded")
export const register = createPostRequest<any, RegisterRequest>(API_CONFIG.REAL_API.NEWUSER_ILX, "application/x-www-form-urlencoded")

export const createNewOrganization = ({group, data} : {group: string, data: any}) => {
const endpoint = `/${group}${API_CONFIG.REAL_API.CREATE_NEW_ORGANIZATION}`;
return createPostRequest<any, any>(endpoint, "application/json")(data);
};

export const getOrganizations = (group: string) => {
const endpoint = `/${group}${API_CONFIG.REAL_API.GET_ORGANIZATIONS}`;
return createGetRequest<any, any>(endpoint, "application/json")();
};
34 changes: 20 additions & 14 deletions src/api/endpoints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,19 @@ const useApi = () => api;
const BASE_GROUP = "base";
const BASE_EXTENSION = "jsonld";

export const getOrganizations = async () => {
/** Call endpoint for retrieving organizations, this is a mock endpoint
created by us */
const { getOrganizations } = useMockApi();
export const getOrganizations = async (group) => {
const { getPrivRoleOtherGroup } = useApi();

/** Call Endpoint */
return await getOrganizations().then((data) => {
return data as Organizations;
return await getPrivRoleOtherGroup(group).then((data) => {
return data;
})
.catch((error) => {
return error;
});
}

export const getOrganization = async (id) => {
/** Call endpoint for retrieving organizations, this is a mock endpoint
created by us */
const { getOrganization } = useMockApi();

/** Call Endpoint */
Expand All @@ -42,8 +38,6 @@ export const getOrganization = async (id) => {
}

export const getOrganizationTerms = async (id) => {
/** Call endpoint for retrieving organizations, this is a mock endpoint
created by us */
const { getOrganizationsTerms } = useMockApi();

/** Call Endpoint */
Expand All @@ -55,6 +49,18 @@ export const getOrganizationTerms = async (id) => {
});
}

export const newOrganization = async (organization) => {
const { postPrivOrgNew } = useApi();

/** Call Endpoint */
return postPrivOrgNew(organization).then((response) => {
return response
})
.catch((error) => {
return error;
});
}

export const getOrganizationCuries = async (id) => {
const { getOrganizationsCuries } = useMockApi();

Expand Down Expand Up @@ -206,10 +212,10 @@ export const searchAll = async (term, filters = {}) => {
}

export const patchTerm = async (group, termID, term) => {
const patchEndpointsIlx= "";
const {patchEndpointsIlx} = useApi();

/** Call Endpoint */
return patchEndpointsIlx(group, termID).then((data) => {
return patchEndpointsIlx(group, termID, term).then((data) => {
let termParsed = getTerm(data.data);
let response = {
status : data.status,
Expand All @@ -224,10 +230,10 @@ export const patchTerm = async (group, termID, term) => {
}

export const addTerm = async (group, term) => {
const { addTerm } = useMockApi();
const { postPrivEntityNew } = useApi();

/** Call Endpoint */
return addTerm(group, term).then((data) => {
return postPrivEntityNew(group, term).then((data) => {
let termParsed = getTerm(data.data);
let response = {
status : data.status,
Expand Down
Loading