feat(web): add user ID and name to transaction details for better tracking
This commit is contained in:
@@ -2,6 +2,7 @@ import { Hono } from "hono";
|
|||||||
import { and, 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 { useDrizzle } from "@/lib/db.js";
|
||||||
import { transaction, chargePoint, connector, idTag } from "@/db/schema.js";
|
import { transaction, chargePoint, connector, idTag } from "@/db/schema.js";
|
||||||
|
import { user } from "@/db/auth-schema.js";
|
||||||
import { ocppConnections } from "@/ocpp/handler.js";
|
import { ocppConnections } from "@/ocpp/handler.js";
|
||||||
import { OCPP_MESSAGE_TYPE } from "@/ocpp/types.js";
|
import { OCPP_MESSAGE_TYPE } from "@/ocpp/types.js";
|
||||||
import type { HonoEnv } from "@/types/hono.ts";
|
import type { HonoEnv } from "@/types/hono.ts";
|
||||||
@@ -47,10 +48,14 @@ app.get("/", async (c) => {
|
|||||||
transaction,
|
transaction,
|
||||||
chargePointIdentifier: chargePoint.chargePointIdentifier,
|
chargePointIdentifier: chargePoint.chargePointIdentifier,
|
||||||
connectorNumber: connector.connectorId,
|
connectorNumber: connector.connectorId,
|
||||||
|
idTagUserId: idTag.userId,
|
||||||
|
idTagUserName: user.name,
|
||||||
})
|
})
|
||||||
.from(transaction)
|
.from(transaction)
|
||||||
.leftJoin(chargePoint, eq(transaction.chargePointId, chargePoint.id))
|
.leftJoin(chargePoint, eq(transaction.chargePointId, chargePoint.id))
|
||||||
.leftJoin(connector, eq(transaction.connectorId, connector.id))
|
.leftJoin(connector, eq(transaction.connectorId, connector.id))
|
||||||
|
.leftJoin(idTag, eq(transaction.idTag, idTag.idTag))
|
||||||
|
.leftJoin(user, eq(idTag.userId, user.id))
|
||||||
.where(whereClause)
|
.where(whereClause)
|
||||||
.orderBy(desc(transaction.startTimestamp))
|
.orderBy(desc(transaction.startTimestamp))
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
@@ -61,6 +66,8 @@ app.get("/", async (c) => {
|
|||||||
...r.transaction,
|
...r.transaction,
|
||||||
chargePointIdentifier: r.chargePointIdentifier,
|
chargePointIdentifier: r.chargePointIdentifier,
|
||||||
connectorNumber: r.connectorNumber,
|
connectorNumber: r.connectorNumber,
|
||||||
|
idTagUserId: r.idTagUserId,
|
||||||
|
idTagUserName: r.idTagUserName,
|
||||||
energyWh:
|
energyWh:
|
||||||
r.transaction.stopMeterValue != null
|
r.transaction.stopMeterValue != null
|
||||||
? r.transaction.stopMeterValue - r.transaction.startMeterValue
|
? r.transaction.stopMeterValue - r.transaction.startMeterValue
|
||||||
|
|||||||
@@ -130,10 +130,22 @@ function RecentTransactions({ txns }: { txns: Transaction[] }) {
|
|||||||
<span className="ml-1 text-xs text-muted">#{tx.connectorNumber}</span>
|
<span className="ml-1 text-xs text-muted">#{tx.connectorNumber}</span>
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-xs text-muted">{tx.idTag}</p>
|
<p className="text-xs text-muted">
|
||||||
|
{tx.idTag}
|
||||||
|
{tx.idTagUserId && (
|
||||||
|
<>
|
||||||
|
<span className="mx-1">·</span>
|
||||||
|
{tx.idTagUserName ?? tx.idTagUserId}
|
||||||
|
<span className="ml-1 opacity-50">({tx.idTagUserId.slice(0, 8)})</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="shrink-0 text-right">
|
<div className="shrink-0 text-right">
|
||||||
<p className="text-sm font-medium tabular-nums text-foreground">{kwh}</p>
|
<p className="text-sm font-medium tabular-nums text-foreground">
|
||||||
|
{kwh}
|
||||||
|
<span className="text-xs"> kWh</span>
|
||||||
|
</p>
|
||||||
<p className="text-xs text-muted">{amount}</p>
|
<p className="text-xs text-muted">{amount}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-16 shrink-0 text-right">
|
<div className="w-16 shrink-0 text-right">
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ export type Transaction = {
|
|||||||
connectorNumber: number | null;
|
connectorNumber: number | null;
|
||||||
idTag: string;
|
idTag: string;
|
||||||
idTagStatus: string | null;
|
idTagStatus: string | null;
|
||||||
|
idTagUserId: string | null;
|
||||||
|
idTagUserName: string | null;
|
||||||
startTimestamp: string;
|
startTimestamp: string;
|
||||||
stopTimestamp: string | null;
|
stopTimestamp: string | null;
|
||||||
startMeterValue: number | null;
|
startMeterValue: number | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user