Some fixes
Paar verbesserungen und Einheitlichkeiten.
This commit is contained in:
1 parent
b2545bbdf1
commit
b5b5f593f5
1 file changed
+13
-13
+13
-13
@@ -1,7 +1,7 @@
|
|||||||
import { prisma } from "@/lib/db/prisma";
|
import { prisma } from "@/lib/db/prisma";
|
||||||
import argon2 from "argon2";
|
import argon2 from "argon2";
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* GetUsers
|
* GetUsers
|
||||||
* Returns all users
|
* Returns all users
|
||||||
*
|
*
|
||||||
@@ -14,11 +14,11 @@ export async function getUsers() {
|
|||||||
id: true,
|
id: true,
|
||||||
username: true,
|
username: true,
|
||||||
role: true,
|
role: true,
|
||||||
}
|
},
|
||||||
|
orderBy: [
|
||||||
|
{ id: "asc" },
|
||||||
|
],
|
||||||
});
|
});
|
||||||
if (!users) {
|
|
||||||
return { success: false, error: "User not found" };
|
|
||||||
}
|
|
||||||
|
|
||||||
return { success: true, users };
|
return { success: true, users };
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
@@ -27,7 +27,7 @@ export async function getUsers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* GetUserById
|
* GetUserById
|
||||||
* Returns a user by his ID
|
* Returns a user by his ID
|
||||||
* @param id - ID indicatin the user
|
* @param id - ID indicatin the user
|
||||||
@@ -55,7 +55,7 @@ export async function getUserById(id: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* GetUserByUsername
|
* GetUserByUsername
|
||||||
* Returns a user by his username
|
* Returns a user by his username
|
||||||
* @param username - Username of the user
|
* @param username - Username of the user
|
||||||
@@ -83,7 +83,7 @@ export async function getUserByUsername(username: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* CreateUser
|
* CreateUser
|
||||||
* Creates an user and returns this user
|
* Creates an user and returns this user
|
||||||
* @param data - object with username, password and optional role
|
* @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 };
|
return { success: true, user };
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
console.error("Error in updateUser", error);
|
console.error("Error in createUser", error);
|
||||||
// P2002 = Unique Constraint Violation
|
// P2002 = Unique Constraint Violation
|
||||||
if (error.code === "P2002") {
|
if (error.code === "P2002") {
|
||||||
return { success: false, error: "Username aready exists",};
|
return { success: false, error: "Username aready exists",};
|
||||||
@@ -120,7 +120,7 @@ export async function CreateUser(data: { username: string; password: string; rol
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* UpdateUser
|
* UpdateUser
|
||||||
* Updates an existing user and returns the updated user
|
* Updates an existing user and returns the updated user
|
||||||
* @param id - ID indicatin the user
|
* @param id - ID indicatin the user
|
||||||
@@ -152,7 +152,7 @@ export async function updateUser(
|
|||||||
return { success: false, error: "No fields provided to update" };
|
return { success: false, error: "No fields provided to update" };
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedUser = await prisma.user.update({
|
const user = await prisma.user.update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: updateData,
|
data: updateData,
|
||||||
select: {
|
select: {
|
||||||
@@ -162,7 +162,7 @@ export async function updateUser(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return { success: true, user: updatedUser };
|
return { success: true, user };
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error in updateUser", error);
|
console.error("Error in updateUser", error);
|
||||||
@@ -178,7 +178,7 @@ export async function updateUser(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* DeleteUser
|
* DeleteUser
|
||||||
* Deletes an existing user and returns the deleted user
|
* Deletes an existing user and returns the deleted user
|
||||||
* @param id - ID indicatin the user
|
* @param id - ID indicatin the user
|
||||||
|
|||||||
Reference in new issue
Block a user