fix(ui): подтверждать сохранение пользователей IPsec
This commit is contained in:
1 parent
f9413d5100
commit
86ecf764ff
7 files changed
+135
-25
No files matched your search
+10
-3
@@ -1,4 +1,4 @@
|
||||
import { ipsecServerSummaryDtoSchema } from "@mmapp/contracts/ipsec"
|
||||
import { ipsecServerSummaryDtoSchema, ipsecUserCreatedSchema } from "@mmapp/contracts/ipsec"
|
||||
import { requestJson } from "@/shared/api/http-client"
|
||||
import type {
|
||||
IpsecCertBundle,
|
||||
@@ -55,10 +55,15 @@ export async function createIpsecUser(
|
||||
baseUrl: string,
|
||||
body: IpsecUserCreateRequest,
|
||||
): Promise<IpsecUserCreated> {
|
||||
return requestJson<IpsecUserCreated>(baseUrl, "/api/ipsec/users", {
|
||||
const response = await requestJson<unknown>(baseUrl, "/api/ipsec/users", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
const result = ipsecUserCreatedSchema.safeParse(response)
|
||||
if (!result.success || result.data.client.serverId !== String(body.serverId) || result.data.client.name !== body.name.trim() || result.data.client.authMethod !== (body.authMethod ?? "certificate")) {
|
||||
throw new Error("Сервер не подтвердил создание клиента")
|
||||
}
|
||||
return result.data
|
||||
}
|
||||
|
||||
export async function patchIpsecUser(
|
||||
@@ -67,11 +72,13 @@ export async function patchIpsecUser(
|
||||
clientId: string,
|
||||
patch: IpsecUserPatch,
|
||||
): Promise<{ ok: boolean }> {
|
||||
return requestJson<{ ok: boolean }>(
|
||||
const result = await requestJson<{ ok: boolean }>(
|
||||
baseUrl,
|
||||
`/api/ipsec/users/${encodeURIComponent(serverId)}/${encodeURIComponent(clientId)}`,
|
||||
{ method: "PATCH", body: JSON.stringify(patch) },
|
||||
)
|
||||
if (result?.ok !== true) throw new Error("Сервер не подтвердил сохранение клиента")
|
||||
return result
|
||||
}
|
||||
|
||||
export async function deleteIpsecUser(
|
||||
|
||||
Reference in new issue
Block a user