From 39106a50c3422ea15f1b9dc868a101f4226af639 Mon Sep 17 00:00:00 2001 From: Thor Lund Hansen Date: Wed, 15 Nov 2023 11:38:03 +0100 Subject: [PATCH] Fixed bug, also validation is an issue on update --- Src/Firebase/users.ts | 7 +++---- Src/routes/users.ts | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Src/Firebase/users.ts b/Src/Firebase/users.ts index c52ae01..9fe62b3 100644 --- a/Src/Firebase/users.ts +++ b/Src/Firebase/users.ts @@ -136,10 +136,8 @@ export async function userLogin( ); } //hashes password in routes intill i know a better way -export async function updateUser(user: User) { - if (!isValidUser(user)) { - throw new BaseError('User is not valid', 400); - } +export async function updateUser(user: User): Promise { + const updateUser = doc(db, 'users', `${user.id}`); await updateDoc(updateUser, { firstName: user.firstName, @@ -150,6 +148,7 @@ export async function updateUser(user: User) { if (!updateUser) { throw new BaseError('User not found', 404); } + return user; } export async function deleteUser(user: User) { diff --git a/Src/routes/users.ts b/Src/routes/users.ts index 68ab5e5..6838622 100644 --- a/Src/routes/users.ts +++ b/Src/routes/users.ts @@ -112,8 +112,8 @@ router.put( password: hashedPassword || user.password, orgId: [parseInt(req.params.orgId)], }; - updateUser(updatedUser); - res.status(204).end(); + const newUserInfo = await updateUser(updatedUser); + res.json(newUserInfo); }), );