feat: add paginated list functions to DB models

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
fuomag9
2026-02-27 17:58:23 +01:00
parent 8555de7b9d
commit 8bf07011f9
3 changed files with 76 additions and 6 deletions
+16 -1
View File
@@ -2,7 +2,7 @@ import db, { nowIso, toIso } from "../db";
import { applyCaddyConfig } from "../caddy";
import { logAuditEvent } from "../audit";
import { proxyHosts } from "../db/schema";
import { desc, eq } from "drizzle-orm";
import { desc, eq, count } from "drizzle-orm";
import { getAuthentikSettings, getGeoBlockSettings, GeoBlockSettings } from "../settings";
const DEFAULT_AUTHENTIK_HEADERS = [
@@ -1329,6 +1329,21 @@ export async function listProxyHosts(): Promise<ProxyHost[]> {
return hosts.map(parseProxyHost);
}
export async function countProxyHosts(): Promise<number> {
const [row] = await db.select({ value: count() }).from(proxyHosts);
return row?.value ?? 0;
}
export async function listProxyHostsPaginated(limit: number, offset: number): Promise<ProxyHost[]> {
const hosts = await db
.select()
.from(proxyHosts)
.orderBy(desc(proxyHosts.createdAt))
.limit(limit)
.offset(offset);
return hosts.map(parseProxyHost);
}
export async function createProxyHost(input: ProxyHostInput, actorUserId: number) {
if (!input.domains || input.domains.length === 0) {
throw new Error("At least one domain must be specified");