diff --git a/backendV2/routes/admin/database/loanDataMgmt.database.js b/backendV2/routes/admin/database/loanDataMgmt.database.js index 5bdee37..776e41f 100644 --- a/backendV2/routes/admin/database/loanDataMgmt.database.js +++ b/backendV2/routes/admin/database/loanDataMgmt.database.js @@ -17,7 +17,10 @@ export const getAllLoans = async () => { }; export const deleteLoanById = async (loanId) => { - const [result] = await pool.query("DELETE FROM loans WHERE id = ?", [loanId]); + const [result] = await pool.query( + "UPDATE loans SET deleted = true, deleted_admin = true WHERE id = ?", + [loanId], + ); if (result.affectedRows > 0) return { success: true }; return { success: false }; }; diff --git a/backendV2/schemeV2.sql b/backendV2/schemeV2.sql index 699e404..24e27cc 100644 --- a/backendV2/schemeV2.sql +++ b/backendV2/schemeV2.sql @@ -27,6 +27,7 @@ CREATE TABLE loans ( loaned_items_id json NOT NULL DEFAULT ('[]'), loaned_items_name json NOT NULL DEFAULT ('[]'), deleted bool NOT NULL DEFAULT false, + deleted_admin bool NOT NULL DEFAULT false, note varchar(500) DEFAULT NULL, PRIMARY KEY (id), CHECK (loan_code REGEXP '^[0-9]{6}$') diff --git a/changelog.md b/changelog.md index 1ae6467..de56962 100644 --- a/changelog.md +++ b/changelog.md @@ -11,9 +11,10 @@ This update provides some new features for the design. It also contains some imp ## Improvements -- The overview page now has the note column and is overall better organised -- I have the error logging for the API route wehre you can take loans improved. +- The overview page now shows the note column and is overall better organised. +- Improved error logging - If you try to delete a loan that has not been returned yet, you will get an 507 error code. +- When the admin deletes a loan, the loan will be still visible in the database, but it will be marked as deleted. This is to prevent data loss and to keep track of deleted loans. ## Fixed bugs