filter out deleted loans in getBorrowableItemsFromDatabase and createLoanInDatabase functions

This commit is contained in:
2025-10-26 13:54:37 +01:00
parent a8821ceca8
commit 71fea52da7

View File

@@ -179,6 +179,7 @@ export const getBorrowableItemsFromDatabase = async (
FROM loans l FROM loans l
JOIN JSON_TABLE(l.loaned_items_id, '$[*]' COLUMNS (item_id INT PATH '$')) jt JOIN JSON_TABLE(l.loaned_items_id, '$[*]' COLUMNS (item_id INT PATH '$')) jt
WHERE jt.item_id = i.id WHERE jt.item_id = i.id
AND l.deleted = 0
AND l.start_date < ? AND l.start_date < ?
AND COALESCE(l.returned_date, l.end_date) > ? AND COALESCE(l.returned_date, l.end_date) > ?
); );
@@ -269,6 +270,7 @@ export const createLoanInDatabase = async (
JOIN JSON_TABLE(l.loaned_items_id, '$[*]' COLUMNS (item_id INT PATH '$')) jt JOIN JSON_TABLE(l.loaned_items_id, '$[*]' COLUMNS (item_id INT PATH '$')) jt
ON TRUE ON TRUE
WHERE jt.item_id IN (?) WHERE jt.item_id IN (?)
AND l.deleted = 0
AND l.start_date < ? AND l.start_date < ?
AND COALESCE(l.returned_date, l.end_date) > ? AND COALESCE(l.returned_date, l.end_date) > ?
`, `,