feat(web): charge point details page

This commit is contained in:
2026-03-10 16:12:38 +08:00
parent 08cd00c802
commit f803a447b5
5 changed files with 654 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
import { Hono } from "hono";
import { desc, eq, isNull, isNotNull, sql } from "drizzle-orm";
import { and, desc, eq, isNull, isNotNull, sql } from "drizzle-orm";
import { useDrizzle } from "@/lib/db.js";
import { transaction, chargePoint, connector, idTag } from "@/db/schema.js";
import { ocppConnections } from "@/ocpp/handler.js";
@@ -12,17 +12,24 @@ app.get("/", async (c) => {
const page = Math.max(1, Number(c.req.query("page") ?? 1));
const limit = Math.min(100, Math.max(1, Number(c.req.query("limit") ?? 20)));
const status = c.req.query("status"); // 'active' | 'completed'
const chargePointId = c.req.query("chargePointId");
const offset = (page - 1) * limit;
const db = useDrizzle();
const whereClause =
const statusCondition =
status === "active"
? isNull(transaction.stopTimestamp)
: status === "completed"
? isNotNull(transaction.stopTimestamp)
: undefined;
const whereClause = chargePointId
? statusCondition
? and(statusCondition, eq(transaction.chargePointId, chargePointId))
: eq(transaction.chargePointId, chargePointId)
: statusCondition;
const [{ total }] = await db
.select({ total: sql<number>`count(*)::int` })
.from(transaction)