diff --git a/lib/db/user.ts b/lib/db/user.ts index 4a51cf9..d7b7be4 100644 --- a/lib/db/user.ts +++ b/lib/db/user.ts @@ -1,7 +1,7 @@ import { prisma } from "@/lib/db/prisma"; import argon2 from "argon2"; -/* +/** * GetUsers * Returns all users * @@ -14,11 +14,11 @@ export async function getUsers() { id: true, username: true, role: true, - } + }, + orderBy: [ + { id: "asc" }, + ], }); - if (!users) { - return { success: false, error: "User not found" }; - } return { success: true, users }; } catch(error) { @@ -27,7 +27,7 @@ export async function getUsers() { } } -/* +/** * GetUserById * Returns a user by his ID * @param id - ID indicatin the user @@ -55,7 +55,7 @@ export async function getUserById(id: number) { } } -/* +/** * GetUserByUsername * Returns a user by his username * @param username - Username of the user @@ -83,7 +83,7 @@ export async function getUserByUsername(username: string) { } } -/* +/** * CreateUser * Creates an user and returns this user * @param data - object with username, password and optional role @@ -111,7 +111,7 @@ export async function CreateUser(data: { username: string; password: string; rol return { success: true, user }; } catch(error) { - console.error("Error in updateUser", error); + console.error("Error in createUser", error); // P2002 = Unique Constraint Violation if (error.code === "P2002") { return { success: false, error: "Username aready exists",}; @@ -120,7 +120,7 @@ export async function CreateUser(data: { username: string; password: string; rol } } -/* +/** * UpdateUser * Updates an existing user and returns the updated user * @param id - ID indicatin the user @@ -152,7 +152,7 @@ export async function updateUser( return { success: false, error: "No fields provided to update" }; } - const updatedUser = await prisma.user.update({ + const user = await prisma.user.update({ where: { id }, data: updateData, select: { @@ -162,7 +162,7 @@ export async function updateUser( } }); - return { success: true, user: updatedUser }; + return { success: true, user }; } catch (error) { console.error("Error in updateUser", error); @@ -178,7 +178,7 @@ export async function updateUser( } } -/* +/** * DeleteUser * Deletes an existing user and returns the deleted user * @param id - ID indicatin the user