68 lines
1.5 KiB
TypeScript
68 lines
1.5 KiB
TypeScript
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;
|
|
taxnumber: string;
|
|
files: File[];
|
|
};
|
|
|
|
type PatchVerificationBody = {
|
|
id?: string;
|
|
status?: "org" | "nko";
|
|
comment?: string;
|
|
accepted?: boolean;
|
|
taxnumber?: string;
|
|
};
|
|
|
|
const baseUrl = process.env.REACT_APP_DOMAIN + "/verification"
|
|
|
|
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,
|
|
url: baseUrl + `/verification`,
|
|
body,
|
|
});
|
|
|
|
return [patchedVerificationResponse];
|
|
} catch (nativeError) {
|
|
const [error] = parseAxiosError(nativeError);
|
|
|
|
return [null, `Ошибка изменения верификации. ${error}`];
|
|
}
|
|
};
|