adminFront/src/api/verification.ts

68 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-09-01 13:17:24 +00:00
import { makeRequest } from "@frontend/kitui";
import { parseAxiosError } from "@root/utils/parse-error";
type File = {
name: "inn" | "rule" | "egrule" | "certificate";
url: string;
};
export type Verification = {
_id: string;
accepted: boolean;
status: "org" | "nko";
updated_at: string;
comment: string;
2023-10-28 21:31:11 +00:00
taxnumber: string;
2023-09-01 13:17:24 +00:00
files: File[];
};
type PatchVerificationBody = {
2023-10-28 21:31:11 +00:00
id?: string;
status?: "org" | "nko";
comment?: string;
accepted?: boolean;
taxnumber?: string;
2023-09-01 13:17:24 +00:00
};
2024-01-23 18:31:02 +00:00
const baseUrl = process.env.REACT_APP_DOMAIN + "/verification"
2023-09-01 13:17:24 +00:00
export const verification = async (
userId: string
): Promise<[Verification | null, string?]> => {
try {
const verificationResponse = await makeRequest<never, Verification>({
method: "get",
url: baseUrl + `/verification/${userId}`,
});
return [verificationResponse];
} catch (nativeError) {
const [error] = parseAxiosError(nativeError);
return [null, `Ошибка верификации. ${error}`];
}
};
export const patchVerification = async (
body: PatchVerificationBody
): Promise<[unknown, string?]> => {
try {
const patchedVerificationResponse = await makeRequest<
PatchVerificationBody,
unknown
>({
method: "patch",
useToken: true,
2023-10-28 21:31:11 +00:00
url: baseUrl + `/verification`,
2023-09-01 13:17:24 +00:00
body,
});
return [patchedVerificationResponse];
} catch (nativeError) {
const [error] = parseAxiosError(nativeError);
return [null, `Ошибка изменения верификации. ${error}`];
}
};