From a78118da8dff30d45c0133fe56ab6bb1d77e5849 Mon Sep 17 00:00:00 2001 From: Theis Gaedigk Date: Sun, 23 Nov 2025 19:33:12 +0100 Subject: [PATCH] refactored backend --- .../routes/admin/database/userDataMgmt.database.js | 4 ++-- backendV2/services/database.js | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backendV2/routes/admin/database/userDataMgmt.database.js b/backendV2/routes/admin/database/userDataMgmt.database.js index f9a58a2..9f92893 100644 --- a/backendV2/routes/admin/database/userDataMgmt.database.js +++ b/backendV2/routes/admin/database/userDataMgmt.database.js @@ -36,7 +36,7 @@ export const deleteUserById = async (userId) => { export const changePassword = async (userId, newPassword) => { const [result] = await pool.query( - "UPDATE users SET password = ? WHERE id = ?", + "UPDATE users SET password = ?, entry_updated_at = NOW() WHERE id = ?", [newPassword, userId] ); if (result.affectedRows > 0) return { success: true }; @@ -52,7 +52,7 @@ export const editUserById = async ( is_admin ) => { const [result] = await pool.query( - "UPDATE users SET first_name = ?, last_name = ?, role = ?, email = ?, is_admin = ? WHERE id = ?", + "UPDATE users SET first_name = ?, last_name = ?, role = ?, email = ?, is_admin = ?, entry_updated_at = NOW() WHERE id = ?", [first_name, last_name, role, email, is_admin, userId] ); if (result.affectedRows > 0) return { success: true }; diff --git a/backendV2/services/database.js b/backendV2/services/database.js index 6a09279..5cb8875 100644 --- a/backendV2/services/database.js +++ b/backendV2/services/database.js @@ -17,7 +17,15 @@ export const verifyAPIKeyDB = async (apiKey) => { [apiKey] ); if (result.length > 0) { - return { valid: true }; + const [lastUsed] = await pool.query( + "UPDATE apiKeys SET last_used_at = NOW() WHERE api_key = ?;", + [apiKey] + ); + if (lastUsed.affectedRows > 0) { + return { valid: true }; + } else { + return { valid: false }; + } } else { return { valid: false }; }