4 Commits

Author SHA1 Message Date
f2bb326040 Merge branch 'dev' into debian12 2025-11-23 21:40:11 +01:00
85e6d7fe00 fixed bugs 2025-11-23 21:39:18 +01:00
4b9f55268c updated scheme 2025-11-23 21:25:08 +01:00
90ca266793 changed docker config 2025-11-23 20:26:49 +01:00
5 changed files with 27 additions and 10 deletions

View File

@@ -68,7 +68,7 @@ const ItemTable: React.FC = () => {
const handleLockerNumberChange = (id: number, value: string) => { const handleLockerNumberChange = (id: number, value: string) => {
setItems((prev) => setItems((prev) =>
prev.map((it) => (it.id === id ? { ...it, lockerNumber: value } : it)) prev.map((it) => (it.id === id ? { ...it, safe_nr: value } : it))
); );
}; };

View File

@@ -200,7 +200,6 @@ export const handleEditItems = async (
safe_nr: string | null, safe_nr: string | null,
can_borrow_role: string can_borrow_role: string
) => { ) => {
const newSafeNr = Number(safe_nr || 0);
try { try {
const response = await fetch( const response = await fetch(
`${API_BASE}/api/admin/item-data/edit-item/${itemId}`, `${API_BASE}/api/admin/item-data/edit-item/${itemId}`,
@@ -210,7 +209,7 @@ export const handleEditItems = async (
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${Cookies.get("token")}`, Authorization: `Bearer ${Cookies.get("token")}`,
}, },
body: JSON.stringify({ item_name, newSafeNr, can_borrow_role }), body: JSON.stringify({ item_name, safe_nr, can_borrow_role }),
} }
); );
if (!response.ok) { if (!response.ok) {

View File

@@ -32,10 +32,21 @@ export const createItem = async (item_name, can_borrow_role, lockerNumber) => {
return { success: false }; return { success: false };
}; };
export const editItemById = async (itemId, item_name, can_borrow_role) => { export const editItemById = async (
itemId,
item_name,
can_borrow_role,
safe_nr
) => {
let newSafeNr;
if (safe_nr === null || safe_nr === "") {
newSafeNr = null;
} else {
newSafeNr = safe_nr;
}
const [result] = await pool.query( const [result] = await pool.query(
"UPDATE items SET item_name = ?, can_borrow_role = ?, entry_updated_at = NOW() WHERE id = ?", "UPDATE items SET item_name = ?, can_borrow_role = ?, safe_nr = ?, entry_updated_at = NOW() WHERE id = ?",
[item_name, can_borrow_role, itemId] [item_name, can_borrow_role, newSafeNr, itemId]
); );
if (result.affectedRows > 0) return { success: true }; if (result.affectedRows > 0) return { success: true };
return { success: false }; return { success: false };

View File

@@ -41,11 +41,13 @@ router.post("/create-item", authenticateAdmin, async (req, res) => {
router.post("/edit-item/:id", authenticateAdmin, async (req, res) => { router.post("/edit-item/:id", authenticateAdmin, async (req, res) => {
const itemId = req.params.id; const itemId = req.params.id;
const { item_name, can_borrow_role } = req.body; const { item_name, can_borrow_role, safe_nr } = req.body;
const result = await editItemById( const result = await editItemById(
itemId, itemId,
item_name, item_name,
can_borrow_role can_borrow_role,
safe_nr
); );
if (result.success) { if (result.success) {
return res.status(200).json({ message: "Item edited successfully" }); return res.status(200).json({ message: "Item edited successfully" });

View File

@@ -37,15 +37,20 @@ CREATE TABLE items (
item_name varchar(255) NOT NULL UNIQUE, item_name varchar(255) NOT NULL UNIQUE,
can_borrow_role INT NOT NULL, can_borrow_role INT NOT NULL,
in_safe bool NOT NULL DEFAULT true, in_safe bool NOT NULL DEFAULT true,
safe_nr CHAR(2) DEFAULT NULL UNIQUE, safe_nr CHAR(2) DEFAULT NULL,
entry_created_at timestamp NULL DEFAULT CURRENT_TIMESTAMP, entry_created_at timestamp NULL DEFAULT CURRENT_TIMESTAMP,
entry_updated_at timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, entry_updated_at timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
last_borrowed_person varchar(255) DEFAULT NULL, last_borrowed_person varchar(255) DEFAULT NULL,
currently_borrowing varchar(255) DEFAULT NULL, currently_borrowing varchar(255) DEFAULT NULL,
PRIMARY KEY (id), PRIMARY KEY (id),
CHECK (safe_nr REGEXP '^[0-9]{2}$' OR safe_nr IS NULL) CHECK (safe_nr REGEXP '^[0-9]{2}$' OR safe_nr IS NULL),
UNIQUE KEY ux_items_safe_nr (safe_nr)
) ENGINE=InnoDB; ) ENGINE=InnoDB;
CREATE UNIQUE INDEX ux_items_safe_nr_not_null
ON items (safe_nr)
WHERE safe_nr IS NOT NULL;
CREATE TABLE apiKeys ( CREATE TABLE apiKeys (
id INT NOT NULL AUTO_INCREMENT, id INT NOT NULL AUTO_INCREMENT,
api_key CHAR(8) NOT NULL UNIQUE, api_key CHAR(8) NOT NULL UNIQUE,