/
useValidateImportApi.ts
42 lines (36 loc) · 1.08 KB
/
useValidateImportApi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import useAPI from '../useApi/useApi';
export interface ImportQuerySchema {
project: string;
environment: string;
data: object;
}
export interface IValidationSchema {
errors: Array<{ message: string; affectedItems: Array<string> }>;
warnings: Array<{ message: string; affectedItems: Array<string> }>;
permissions: Array<{ message: string; affectedItems: Array<string> }>;
}
export const useValidateImportApi = () => {
const { makeRequest, createRequest, errors, loading } = useAPI({
propagateErrors: true,
});
const validateImport = async (
payload: ImportQuerySchema
): Promise<IValidationSchema> => {
const path = `api/admin/features-batch/full-validate`;
const req = createRequest(path, {
method: 'POST',
body: JSON.stringify(payload),
});
try {
const res = await makeRequest(req.caller, req.id);
return res.json();
} catch (e) {
throw e;
}
};
return {
loading,
errors,
validateImport,
};
};