Refactor code
This commit is contained in:
@ -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(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user