2023-11-05 23:33:40 +00:00
|
|
|
import { makeRequest } from "@frontend/kitui"
|
2023-07-06 21:52:07 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
import { jsonToFormdata } from "@root/utils/jsonToFormdata"
|
|
|
|
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 {
|
2023-11-05 23:33:40 +00:00
|
|
|
Verification,
|
|
|
|
SendDocumentsArgs,
|
|
|
|
UpdateDocumentsArgs,
|
|
|
|
} from "@root/model/auth"
|
2023-07-06 21:52:07 +00:00
|
|
|
|
2024-01-17 19:22:15 +00:00
|
|
|
const apiUrl = "https://" + process.env.REACT_APP_DOMAIN + "/verification"
|
2023-07-06 21:52:07 +00:00
|
|
|
|
2023-08-30 13:50:13 +00:00
|
|
|
export async function verification(
|
2023-11-05 23:33:40 +00:00
|
|
|
userId: string
|
2023-08-30 13:50:13 +00:00
|
|
|
): Promise<[Verification | null, string?]> {
|
2023-11-05 23:33:40 +00:00
|
|
|
try {
|
|
|
|
const verificationResponse = await makeRequest<never, Verification>({
|
|
|
|
url: apiUrl + "/verification/" + userId,
|
|
|
|
method: "GET",
|
|
|
|
useToken: true,
|
|
|
|
withCredentials: true,
|
|
|
|
})
|
2023-08-30 13:50:13 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
return [verificationResponse]
|
|
|
|
} catch (nativeError) {
|
|
|
|
const [error] = parseAxiosError(nativeError)
|
2023-08-30 13:50:13 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
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(
|
2023-11-05 23:33:40 +00:00
|
|
|
documents: SendDocumentsArgs
|
2023-10-27 23:13:54 +00:00
|
|
|
): Promise<[Verification | "OK" | null, string?]> {
|
2023-11-05 23:33:40 +00:00
|
|
|
try {
|
|
|
|
const sendDocumentsResponse = await makeRequest<FormData, Verification>({
|
|
|
|
url: apiUrl + "/verification",
|
|
|
|
method: "POST",
|
|
|
|
useToken: true,
|
|
|
|
withCredentials: true,
|
|
|
|
body: jsonToFormdata({ ...documents, egrule: documents.inn }),
|
|
|
|
})
|
2023-08-30 13:50:13 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
return [sendDocumentsResponse]
|
|
|
|
} catch (nativeError) {
|
|
|
|
const [error] = parseAxiosError(nativeError)
|
2023-07-09 10:30:29 +00:00
|
|
|
|
2023-11-05 23:33:40 +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(
|
2023-11-05 23:33:40 +00:00
|
|
|
documents: UpdateDocumentsArgs
|
2023-10-27 23:13:54 +00:00
|
|
|
): Promise<[Verification | "OK" | null, string? ]> {
|
2023-11-05 23:33:40 +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
|
|
|
|
),
|
|
|
|
})
|
2023-09-15 12:28:46 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
return [updateDocumentsResponse]
|
|
|
|
} catch (nativeError) {
|
|
|
|
const [error] = parseAxiosError(nativeError)
|
2023-09-15 12:28:46 +00:00
|
|
|
|
2023-11-05 23:33:40 +00:00
|
|
|
return [null, `Ошибка обновления документов. ${error}`]
|
|
|
|
}
|
2023-09-15 12:28:46 +00:00
|
|
|
}
|