2022-03-07 11:04:02 +05:30
|
|
|
/*
|
2022-12-27 12:37:58 +05:30
|
|
|
* Copyright 2022 Collate.
|
2022-03-07 11:04:02 +05:30
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { AxiosResponse } from 'axios';
|
|
|
|
import { Operation } from 'fast-json-patch';
|
2023-01-17 21:02:35 +05:30
|
|
|
import { CSVImportResult } from 'generated/type/csvImportResult';
|
2023-01-10 20:04:51 +05:30
|
|
|
import { ModifiedGlossaryData } from 'pages/GlossaryPage/GlossaryPageV1.component';
|
2022-03-07 11:04:02 +05:30
|
|
|
import { CreateGlossary } from '../generated/api/data/createGlossary';
|
|
|
|
import { CreateGlossaryTerm } from '../generated/api/data/createGlossaryTerm';
|
2022-08-08 18:29:05 +05:30
|
|
|
import { Glossary } from '../generated/entity/data/glossary';
|
|
|
|
import { GlossaryTerm } from '../generated/entity/data/glossaryTerm';
|
2022-03-07 11:04:02 +05:30
|
|
|
import { getURLWithQueryFields } from '../utils/APIUtils';
|
|
|
|
import APIClient from './index';
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
export const getGlossaries = async (
|
2022-03-07 11:04:02 +05:30
|
|
|
paging = '',
|
|
|
|
limit = 10,
|
2022-08-08 18:29:05 +05:30
|
|
|
arrQueryFields: string | string[] = ''
|
|
|
|
) => {
|
2022-03-07 11:04:02 +05:30
|
|
|
const qParams = `limit=${limit}`;
|
|
|
|
const url = getURLWithQueryFields(`/glossaries`, arrQueryFields, qParams);
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
const response = await APIClient.get<{ data: ModifiedGlossaryData[] }>(
|
|
|
|
paging ? `${url}&${paging}` : url
|
|
|
|
);
|
|
|
|
|
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
export const addGlossaries = async (data: CreateGlossary) => {
|
2022-03-07 11:04:02 +05:30
|
|
|
const url = '/glossaries';
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
const response = await APIClient.post<
|
|
|
|
CreateGlossary,
|
|
|
|
AxiosResponse<Glossary>
|
|
|
|
>(url, data);
|
|
|
|
|
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
export const updateGlossaries = (
|
|
|
|
data: CreateGlossary
|
|
|
|
): Promise<AxiosResponse> => {
|
|
|
|
const url = '/glossaries';
|
|
|
|
|
|
|
|
return APIClient.put(url, data);
|
|
|
|
};
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
export const patchGlossaries = async (id: string, patch: Operation[]) => {
|
2022-03-07 11:04:02 +05:30
|
|
|
const configOptions = {
|
|
|
|
headers: { 'Content-type': 'application/json-patch+json' },
|
|
|
|
};
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
const response = await APIClient.patch<Operation[], AxiosResponse<Glossary>>(
|
|
|
|
`/glossaries/${id}`,
|
|
|
|
patch,
|
|
|
|
configOptions
|
|
|
|
);
|
|
|
|
|
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
export const getGlossariesByName = async (
|
2022-03-07 11:04:02 +05:30
|
|
|
glossaryName: string,
|
|
|
|
arrQueryFields: string | string[]
|
2022-08-08 18:29:05 +05:30
|
|
|
) => {
|
2022-03-07 11:04:02 +05:30
|
|
|
const url = getURLWithQueryFields(
|
|
|
|
`/glossaries/name/${glossaryName}`,
|
|
|
|
arrQueryFields
|
|
|
|
);
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
const response = await APIClient.get<Glossary>(url);
|
|
|
|
|
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
export const getGlossaryTerms = (
|
2022-03-07 11:04:02 +05:30
|
|
|
glossaryId = '',
|
|
|
|
limit = 10,
|
2022-08-08 18:29:05 +05:30
|
|
|
arrQueryFields: string | string[] = ''
|
|
|
|
): Promise<AxiosResponse<{ data: GlossaryTerm[] }>> => {
|
2022-03-07 11:04:02 +05:30
|
|
|
let qParams = `limit=${limit}`;
|
|
|
|
qParams += glossaryId ? `&glossary=${glossaryId}` : '';
|
|
|
|
const url = getURLWithQueryFields(`/glossaryTerms`, arrQueryFields, qParams);
|
|
|
|
|
|
|
|
return APIClient.get(url);
|
|
|
|
};
|
|
|
|
|
2022-12-29 19:18:48 +05:30
|
|
|
export const getGlossaryTermsById = (
|
2022-03-07 11:04:02 +05:30
|
|
|
glossaryTermId = '',
|
|
|
|
arrQueryFields = ''
|
|
|
|
): Promise<AxiosResponse> => {
|
|
|
|
const url = getURLWithQueryFields(
|
|
|
|
`/glossaryTerms/${glossaryTermId}`,
|
|
|
|
arrQueryFields
|
|
|
|
);
|
|
|
|
|
|
|
|
return APIClient.get(url);
|
|
|
|
};
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
export const getGlossaryTermByFQN = async (
|
2022-03-07 11:04:02 +05:30
|
|
|
glossaryTermFQN = '',
|
2022-08-08 18:29:05 +05:30
|
|
|
arrQueryFields: string | string[] = ''
|
|
|
|
) => {
|
2022-03-07 11:04:02 +05:30
|
|
|
const url = getURLWithQueryFields(
|
|
|
|
`/glossaryTerms/name/${glossaryTermFQN}`,
|
|
|
|
arrQueryFields
|
|
|
|
);
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
const response = await APIClient.get<GlossaryTerm>(url);
|
|
|
|
|
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
export const addGlossaryTerm = (
|
|
|
|
data: CreateGlossaryTerm
|
|
|
|
): Promise<AxiosResponse> => {
|
|
|
|
const url = '/glossaryTerms';
|
|
|
|
|
|
|
|
return APIClient.post(url, data);
|
|
|
|
};
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
export const patchGlossaryTerm = async (id: string, patch: Operation[]) => {
|
2022-03-07 11:04:02 +05:30
|
|
|
const configOptions = {
|
|
|
|
headers: { 'Content-type': 'application/json-patch+json' },
|
|
|
|
};
|
|
|
|
|
2022-08-08 18:29:05 +05:30
|
|
|
const response = await APIClient.patch<Operation[], AxiosResponse<Glossary>>(
|
|
|
|
`/glossaryTerms/${id}`,
|
|
|
|
patch,
|
|
|
|
configOptions
|
|
|
|
);
|
|
|
|
|
|
|
|
return response.data;
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteGlossary = (id: string) => {
|
2022-06-08 23:04:41 +05:30
|
|
|
return APIClient.delete(`/glossaries/${id}?recursive=true&hardDelete=true`);
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteGlossaryTerm = (id: string) => {
|
2022-06-08 23:04:41 +05:30
|
|
|
return APIClient.delete(
|
|
|
|
`/glossaryTerms/${id}?recursive=true&hardDelete=true`
|
|
|
|
);
|
2022-03-07 11:04:02 +05:30
|
|
|
};
|
2023-01-17 21:02:35 +05:30
|
|
|
|
|
|
|
export const exportGlossaryInCSVFormat = async (glossaryName: string) => {
|
|
|
|
const response = await APIClient.get<string>(
|
|
|
|
`/glossaries/name/${glossaryName}/export`
|
|
|
|
);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const importGlossaryInCSVFormat = async (
|
|
|
|
glossaryName: string,
|
|
|
|
data: string,
|
|
|
|
dryRun = true
|
|
|
|
) => {
|
|
|
|
const configOptions = {
|
|
|
|
headers: { 'Content-type': 'text/plain' },
|
|
|
|
};
|
|
|
|
const response = await APIClient.put<string, AxiosResponse<CSVImportResult>>(
|
|
|
|
`/glossaries/name/${glossaryName}/import?dryRun=${dryRun}`,
|
|
|
|
data,
|
|
|
|
configOptions
|
|
|
|
);
|
|
|
|
|
|
|
|
return response.data;
|
|
|
|
};
|