feat: add door_key field to items and update related logic in forms and database
This commit is contained in:
@@ -117,11 +117,19 @@ export const getAllLoansV2 = async () => {
|
||||
|
||||
export const openDoor = async (doorKey) => {
|
||||
const [result] = await pool.query(
|
||||
"SELECT lockers FROM doorKeys WHERE door_key = ?;",
|
||||
"SELECT safe_nr, id FROM items WHERE door_key = ?;",
|
||||
[doorKey]
|
||||
);
|
||||
if (result.length > 0) {
|
||||
return { success: true, data: result[0] };
|
||||
const [changeItemSate] = await pool.query(
|
||||
"UPDATE items SET in_safe = NOT in_safe WHERE id = ?",
|
||||
[result[0].id]
|
||||
);
|
||||
if (changeItemSate.affectedRows > 0) {
|
||||
return { success: true, data: result[0] };
|
||||
} else {
|
||||
return { success: false };
|
||||
}
|
||||
}
|
||||
return { success: false };
|
||||
};
|
||||
|
||||
@@ -80,6 +80,7 @@ router.post(
|
||||
}
|
||||
);
|
||||
|
||||
// Route for API to open a door
|
||||
router.get("/open-door/:key/:doorKey", authenticate, async (req, res) => {
|
||||
const doorKey = req.params.doorKey;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user