42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import type { BUN_SQLITE_WGUI_HOSTS } from "@/db/types/db";
|
|
import grabClients from "@/src/functions/backend/db/clients/grab-clients";
|
|
import grabClientRules from "@/src/functions/backend/db/client-rules/grab-client-rules";
|
|
import type { PagePropsType, PageQueryObject, TableType } from "@/src/types";
|
|
import BunSQLite from "@moduletrace/bun-sqlite";
|
|
import type { BunextPageServerFn } from "@moduletrace/bunext/types";
|
|
|
|
const server: BunextPageServerFn<PagePropsType> = async ({
|
|
req,
|
|
url,
|
|
query,
|
|
}) => {
|
|
const page_query = query as PageQueryObject;
|
|
|
|
const host_record_res = await BunSQLite.select<
|
|
BUN_SQLITE_WGUI_HOSTS,
|
|
TableType
|
|
>({ table: "hosts", targetId: page_query.host_id });
|
|
|
|
const host_clients = await grabClients({
|
|
host_id: page_query.host_id,
|
|
});
|
|
|
|
const clients = host_clients.payload || null;
|
|
|
|
const client_rules = await grabClientRules({
|
|
client_ids: (clients || [])
|
|
.map((client) => client.id)
|
|
.filter((id): id is number => Boolean(id)),
|
|
});
|
|
|
|
return {
|
|
props: {
|
|
host: host_record_res.singleRes || null,
|
|
clients,
|
|
client_rules,
|
|
},
|
|
};
|
|
};
|
|
|
|
export default server;
|