2023-07-06 21:52:07 +00:00
|
|
|
import { makeRequest } from "@frontend/kitui";
|
|
|
|
|
2023-08-30 07:38:33 +00:00
|
|
|
import { jsonToFormdata } from "@root/utils/jsonToFormdata";
|
2023-08-30 13:50:13 +00:00
|
|
|
import { parseAxiosError } from "@root/utils/parse-error";
|
2023-07-09 10:30:29 +00:00
|
|
|
|
2023-09-15 12:28:46 +00:00
|
|
|
import type {
|
|
|
|
Verification,
|
|
|
|
SendDocumentsArgs,
|
|
|
|
UpdateDocumentsArgs,
|
|
|
|
} from "@root/model/auth";
|
2023-07-06 21:52:07 +00:00
|
|
|
|
|
|
|
const apiUrl =
|
2023-08-31 10:02:11 +00:00
|
|
|
process.env.NODE_ENV === "production"
|
|
|
|
? "/verification"
|
|
|
|
: "https://hub.pena.digital/verification";
|
2023-07-06 21:52:07 +00:00
|
|
|
|
2023-08-30 13:50:13 +00:00
|
|
|
export async function verification(
|
|
|
|
userId: string
|
|
|
|
): Promise<[Verification | null, string?]> {
|
|
|
|
try {
|
|
|
|
const verificationResponse = await makeRequest<never, Verification>({
|
2023-09-06 09:02:17 +00:00
|
|
|
url: apiUrl + "/verification/" + userId,
|
2023-08-30 13:50:13 +00:00
|
|
|
method: "GET",
|
|
|
|
useToken: true,
|
|
|
|
withCredentials: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
return [verificationResponse];
|
|
|
|
} catch (nativeError) {
|
|
|
|
const [error] = parseAxiosError(nativeError);
|
|
|
|
|
|
|
|
return [null, `Ошибка запроса верификации. ${error}`];
|
|
|
|
}
|
2023-07-06 21:52:07 +00:00
|
|
|
}
|
2023-07-09 10:30:29 +00:00
|
|
|
|
2023-08-30 13:50:13 +00:00
|
|
|
export async function sendDocuments(
|
|
|
|
documents: SendDocumentsArgs
|
2023-10-27 23:13:54 +00:00
|
|
|
): Promise<[Verification | "OK" | null, string?]> {
|
2023-08-30 13:50:13 +00:00
|
|
|
try {
|
|
|
|
const sendDocumentsResponse = await makeRequest<FormData, Verification>({
|
2023-08-31 10:02:11 +00:00
|
|
|
url: apiUrl + "/verification",
|
2023-08-30 13:50:13 +00:00
|
|
|
method: "POST",
|
|
|
|
useToken: true,
|
|
|
|
withCredentials: true,
|
|
|
|
body: jsonToFormdata({ ...documents, egrule: documents.inn }),
|
|
|
|
});
|
|
|
|
|
|
|
|
return [sendDocumentsResponse];
|
|
|
|
} catch (nativeError) {
|
|
|
|
const [error] = parseAxiosError(nativeError);
|
2023-07-09 10:30:29 +00:00
|
|
|
|
2023-08-30 13:50:13 +00:00
|
|
|
return [null, `Ошибка отправки документов. ${error}`];
|
|
|
|
}
|
2023-07-09 10:30:29 +00:00
|
|
|
}
|
2023-09-15 12:28:46 +00:00
|
|
|
|
|
|
|
export async function updateDocuments(
|
|
|
|
documents: UpdateDocumentsArgs
|
2023-10-27 23:13:54 +00:00
|
|
|
): Promise<[Verification | "OK" | null, string? ]> {
|
2023-09-15 12:28:46 +00:00
|
|
|
try {
|
|
|
|
const updateDocumentsResponse = await makeRequest<FormData, Verification>({
|
|
|
|
url: apiUrl + "/verification/file",
|
|
|
|
method: "PATCH",
|
|
|
|
useToken: true,
|
|
|
|
withCredentials: true,
|
|
|
|
body: jsonToFormdata(
|
|
|
|
documents.inn ? { ...documents, egrule: documents.inn } : documents
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
|
|
|
return [updateDocumentsResponse];
|
|
|
|
} catch (nativeError) {
|
|
|
|
const [error] = parseAxiosError(nativeError);
|
|
|
|
|
|
|
|
return [null, `Ошибка обновления документов. ${error}`];
|
|
|
|
}
|
|
|
|
}
|