124_webcalibre2/src/data-access/users.ts

42 lines
882 B
TypeScript
Raw Normal View History

2026-01-16 05:22:00 +00:00
import "server-only";
import { prisma } from "@/lib/prisma";
/**
* FETCH: Get user by Email
* Used for authorization checks in actions.
*/
export async function getUserByEmail(email: string) {
return await prisma.user.findUnique({
where: { email },
select: { id: true, email: true, role: true }
});
}
/**
* FETCH: Get user by ID
*/
export async function getUserById(id: string) {
return await prisma.user.findUnique({
where: { id },
select: { id: true, email: true, role: true }
});
}
/**
* UPDATE: Update user role
*/
export async function updateUserRole(id: string, role: "ADMIN" | "USER") {
return await prisma.user.update({
where: { id },
data: { role }
});
}
/**
* FETCH: List all users (for the settings table)
*/
export async function getAllUsers() {
return await prisma.user.findMany({
orderBy: { email: 'asc' }
});
}