Complete client form

This commit is contained in:
2026-09-17 08:43:00 +01:00
parent 90ee3debf0
commit cda6cff34f
19 changed files with 661 additions and 4 deletions
@@ -0,0 +1,57 @@
import type {
BUN_SQLITE_WGUI_CLIENTS,
BUN_SQLITE_WGUI_HOSTS,
} from "@/db/types/db";
import setupWireguardClient from "@/src/functions/backend/setup/setup-wireguard-client";
import type { TableType, User } from "@/src/types";
import BunSQLite from "@moduletrace/bun-sqlite";
import type { APIResponseObject } from "@moduletrace/bunext/types";
type Params = {
client_id?: string | number;
user: User;
};
export default async function runClientSetup({
client_id,
user,
}: Params): Promise<APIResponseObject> {
if (!client_id) {
return {
success: false,
msg: `No client id provided`,
};
}
const client_res = await BunSQLite.select<
BUN_SQLITE_WGUI_CLIENTS,
TableType
>({
table: "clients",
targetId: client_id,
});
const client = client_res.singleRes;
if (!client) {
return {
success: false,
msg: `Client record not found`,
};
}
let host: BUN_SQLITE_WGUI_HOSTS | undefined;
if (client?.host_id) {
const host_res = await BunSQLite.select<BUN_SQLITE_WGUI_HOSTS, TableType>(
{
table: "hosts",
targetId: client.host_id,
},
);
host = host_res.singleRes || undefined;
}
return await setupWireguardClient({ client, host, user });
}