zen: fix usage graph

This commit is contained in:
Frank
2026-02-06 00:22:06 -05:00
parent 8bf97ef9e5
commit 0f1fdeceda

View File

@@ -1,4 +1,4 @@
import { and, Database, eq, gte, inArray, isNull, lte, or, sql, sum } from "@opencode-ai/console-core/drizzle/index.js" import { and, Database, eq, gte, inArray, isNull, lt, or, sql, sum } from "@opencode-ai/console-core/drizzle/index.js"
import { UsageTable } from "@opencode-ai/console-core/schema/billing.sql.js" import { UsageTable } from "@opencode-ai/console-core/schema/billing.sql.js"
import { KeyTable } from "@opencode-ai/console-core/schema/key.sql.js" import { KeyTable } from "@opencode-ai/console-core/schema/key.sql.js"
import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js" import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
@@ -27,7 +27,7 @@ async function getCosts(workspaceID: string, year: number, month: number) {
"use server" "use server"
return withActor(async () => { return withActor(async () => {
const startDate = new Date(year, month, 1) const startDate = new Date(year, month, 1)
const endDate = new Date(year, month + 1, 0) const endDate = new Date(year, month + 1, 1)
const usageData = await Database.use((tx) => const usageData = await Database.use((tx) =>
tx tx
.select({ .select({
@@ -42,7 +42,7 @@ async function getCosts(workspaceID: string, year: number, month: number) {
and( and(
eq(UsageTable.workspaceID, workspaceID), eq(UsageTable.workspaceID, workspaceID),
gte(UsageTable.timeCreated, startDate), gte(UsageTable.timeCreated, startDate),
lte(UsageTable.timeCreated, endDate), lt(UsageTable.timeCreated, endDate),
), ),
) )
.groupBy( .groupBy(