From 1ce8d33b0d7eb9e78cf0c21ddb24f67f19cb8c71 Mon Sep 17 00:00:00 2001 From: Theis Gaedigk Date: Sat, 9 May 2026 23:32:12 +0200 Subject: [PATCH 1/5] pulled naas --- no-as-a-service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/no-as-a-service b/no-as-a-service index 764062a..e6b4218 160000 --- a/no-as-a-service +++ b/no-as-a-service @@ -1 +1 @@ -Subproject commit 764062a307c725cb55f56308ee842f5e42529dd1 +Subproject commit e6b4218394f3ab6c513caaf2ec2e3e88d03d124c From fd43e84c0c45c3af6266420caf4498643773e09b Mon Sep 17 00:00:00 2001 From: Theis Gaedigk Date: Mon, 11 May 2026 22:40:34 +0200 Subject: [PATCH 2/5] refactored code --- backendV2/routes/app/database/loansMgmt.database.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/backendV2/routes/app/database/loansMgmt.database.js b/backendV2/routes/app/database/loansMgmt.database.js index aa9a261..34b8c72 100644 --- a/backendV2/routes/app/database/loansMgmt.database.js +++ b/backendV2/routes/app/database/loansMgmt.database.js @@ -63,11 +63,9 @@ export const createLoanInDatabase = async ( }; } - const itemNames = itemIds - .map( - (id) => itemsRows.find((r) => Number(r.id) === Number(id))?.item_name, - ) - .filter(Boolean); + const itemNames = itemIds.map( + (id) => itemsRows.find((r) => Number(r.id) === Number(id)).item_name, + ); // Build lockers array (unique, only 2-digit numbers from safe_nr) const lockers = [ From 831de8b6101a63fbb33d71b20d0aa85abe1fa6e2 Mon Sep 17 00:00:00 2001 From: Theis Gaedigk Date: Wed, 13 May 2026 14:04:12 +0200 Subject: [PATCH 3/5] added new loan code function - NOT TESTED YET --- .../routes/app/database/loansMgmt.database.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/backendV2/routes/app/database/loansMgmt.database.js b/backendV2/routes/app/database/loansMgmt.database.js index 34b8c72..1b48d41 100644 --- a/backendV2/routes/app/database/loansMgmt.database.js +++ b/backendV2/routes/app/database/loansMgmt.database.js @@ -107,6 +107,32 @@ export const createLoanInDatabase = async ( }; } + let index = false; + let candidate = Math.floor(100000 + Math.random() * 899999); // 6 digits + + try { + const [exists] = await conn.query( + "SELECT 1 FROM loans WHERE loan_code = ? LIMIT 1", + [candidate], + ); + } catch (error) { + while ((i = false)) { + candidate = Math.floor(100000 + Math.random() * 899999); // 6 digits + + const [exists] = await conn.query( + "SELECT 1 FROM loans WHERE loan_code = ? LIMIT 1", + [candidate], + ); + + // sets index to true if the 6 digit code does not exist + if (exists.length == 0) { + index = true; + } + } + } + + /* + // Generate unique loan_code (retry a few times) let loanCode = null; for (let i = 0; i < 6; i++) { @@ -128,6 +154,8 @@ export const createLoanInDatabase = async ( message: "Failed to generate unique loan code", }; } + + */ // Insert loan (now includes lockers) const [insertRes] = await conn.query( From 67c704009e3fd9fd5e1721880faac8f5a6fcb289 Mon Sep 17 00:00:00 2001 From: Theis Gaedigk Date: Wed, 13 May 2026 19:42:54 +0200 Subject: [PATCH 4/5] refactored loan code creation function --- .../routes/app/database/loansMgmt.database.js | 53 ++++--------------- 1 file changed, 11 insertions(+), 42 deletions(-) diff --git a/backendV2/routes/app/database/loansMgmt.database.js b/backendV2/routes/app/database/loansMgmt.database.js index 1b48d41..f02ea65 100644 --- a/backendV2/routes/app/database/loansMgmt.database.js +++ b/backendV2/routes/app/database/loansMgmt.database.js @@ -108,54 +108,23 @@ export const createLoanInDatabase = async ( } let index = false; - let candidate = Math.floor(100000 + Math.random() * 899999); // 6 digits + let candidate; + let loanCode; - try { - const [exists] = await conn.query( - "SELECT 1 FROM loans WHERE loan_code = ? LIMIT 1", + // Generates 6-digit loan code + do { + candidate = Math.floor(100000 + Math.random() * 899999); + + const [rows] = await conn.query( + "SELECT 1 FROM loans where loan_code = ? LIMIT 1", [candidate], ); - } catch (error) { - while ((i = false)) { - candidate = Math.floor(100000 + Math.random() * 899999); // 6 digits - const [exists] = await conn.query( - "SELECT 1 FROM loans WHERE loan_code = ? LIMIT 1", - [candidate], - ); - - // sets index to true if the 6 digit code does not exist - if (exists.length == 0) { - index = true; - } - } - } - - /* - - // Generate unique loan_code (retry a few times) - let loanCode = null; - for (let i = 0; i < 6; i++) { - const candidate = Math.floor(100000 + Math.random() * 899999); // 6 digits - const [exists] = await conn.query( - "SELECT 1 FROM loans WHERE loan_code = ? LIMIT 1", - [candidate], - ); - if (exists.length === 0) { + if (rows.length == 0) { + index = true; loanCode = candidate; - break; } - } - if (!loanCode) { - await conn.rollback(); - return { - success: false, - code: "SERVER_ERROR", - message: "Failed to generate unique loan code", - }; - } - - */ + } while (index === false); // Insert loan (now includes lockers) const [insertRes] = await conn.query( From 929ec5ef10b098c74587afeb21d7b8d8056e48d8 Mon Sep 17 00:00:00 2001 From: Theis Gaedigk Date: Wed, 15 Jul 2026 15:40:08 +0200 Subject: [PATCH 5/5] fix: Fix issue/ticket #17 --- backendV2/routes/admin/database/loanDataMgmt.database.js | 2 +- backendV2/routes/api/api.database.js | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/backendV2/routes/admin/database/loanDataMgmt.database.js b/backendV2/routes/admin/database/loanDataMgmt.database.js index 776e41f..81d2c55 100644 --- a/backendV2/routes/admin/database/loanDataMgmt.database.js +++ b/backendV2/routes/admin/database/loanDataMgmt.database.js @@ -12,7 +12,7 @@ const pool = mysql .promise(); export const getAllLoans = async () => { - const [rows] = await pool.query("SELECT * FROM loans"); + const [rows] = await pool.query("SELECT * FROM loans WHERE deleted_admin = 0;"); return { success: true, data: rows }; }; diff --git a/backendV2/routes/api/api.database.js b/backendV2/routes/api/api.database.js index d0a13d3..f42f417 100644 --- a/backendV2/routes/api/api.database.js +++ b/backendV2/routes/api/api.database.js @@ -119,14 +119,6 @@ export const setTakeDateV2 = async (loanCode) => { return { message: "Failed to set take date", success: false }; }; -export const getAllLoansV2 = async () => { - const [result] = await pool.query("SELECT * FROM loans;"); - if (result.length > 0) { - return { success: true, data: result }; - } - return { success: false }; -}; - export const openDoor = async (doorKey) => { const [result] = await pool.query( "SELECT safe_nr, id FROM items WHERE door_key = ?;",