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