Refactor code

This commit is contained in:
2026-02-03 13:12:31 +01:00
parent 8572e22c5d
commit 531bb8750e
23 changed files with 106 additions and 48 deletions

View File

@ -2,9 +2,9 @@
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { headers } from "next/headers";
import type { SessionWithRole } from "@/types/auth";
import type { UsersListRow } from "@/types/users";
import type { UserRole, UsersListRow } from "@/types/users";
import { headers } from "next/headers";
// Returns all users for the admin users table.
export async function getUsers(): Promise<UsersListRow[]> {
@ -28,9 +28,16 @@ export async function getUsers(): Promise<UsersListRow[]> {
},
});
return rows.map((r) => ({
...r,
createdAt: r.createdAt.toISOString(),
updatedAt: r.updatedAt.toISOString(),
}));
return rows.map((r) => {
if (r.role !== "admin" && r.role !== "user") {
throw new Error(`Unexpected user role: ${r.role}`);
}
return {
...r,
role: r.role as UserRole,
createdAt: r.createdAt.toISOString(),
updatedAt: r.updatedAt.toISOString(),
};
});
}