refactor(db): finish Drizzle migration for remaining actions and services

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
SimoandCursor committed 2026-08-01 13:27:59 +02:00
1 parent 22234fe102
commit 65b2fbee6a
19 files changed
+422 -342

No files matched your search

+30 -16
View File
@@ -1,25 +1,39 @@
import { count, desc, eq } from "drizzle-orm";
import type { OnlineUser } from "@/components/admin/dashboard";
import { prisma } from "@/lib/prisma";
import { db, User } from "@/lib/db";
/** Shared online roster used by CommandoCentrum (and linked from other ops hubs). */
export async function fetchOpsOnlineUsers(
limit = 40,
): Promise<{ count: number; users: OnlineUser[] }> {
const [count, onlineUsersRaw] = await Promise.all([
prisma.user.count({ where: { online: "1" } }).catch(() => 0),
prisma.user
.findMany({
where: { online: "1" },
select: {
id: true,
username: true,
look: true,
lastOnline: true,
},
orderBy: { lastOnline: "desc" },
take: limit,
const [countRow, onlineUsersRaw] = await Promise.all([
db
.select({ total: count() })
.from(User)
.where(eq(User.online, "1"))
.then((rows) => rows[0]?.total ?? 0)
.catch(() => 0),
db
.select({
id: User.id,
username: User.username,
look: User.look,
lastOnline: User.lastOnline,
})
.catch(() => []),
.from(User)
.where(eq(User.online, "1"))
.orderBy(desc(User.lastOnline))
.limit(limit)
.then((rows) => rows)
.catch(
() =>
[] as Array<{
id: number;
username: string;
look: string;
lastOnline: number;
}>,
),
]);
const users: OnlineUser[] = onlineUsersRaw.map((u) => ({
@@ -31,5 +45,5 @@ export async function fetchOpsOnlineUsers(
lastActivity: u.lastOnline > 0 ? new Date(u.lastOnline * 1000) : new Date(),
}));
return { count, users };
return { count: countRow, users };
}