edited scheme but still not working
This commit is contained in:
@@ -114,3 +114,14 @@ export const getAllLoansV2 = async () => {
|
||||
}
|
||||
return { success: false };
|
||||
};
|
||||
|
||||
export const openDoor = async (doorKey) => {
|
||||
const [result] = await pool.query(
|
||||
"SELECT lockers FROM doorKeys WHERE door_key = ?;",
|
||||
[doorKey]
|
||||
);
|
||||
if (result.length > 0) {
|
||||
return { success: true, data: result[0] };
|
||||
}
|
||||
return { success: false };
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
setTakeDateV2,
|
||||
setReturnDateV2,
|
||||
getLoanByCodeV2,
|
||||
openDoor,
|
||||
} from "./api.database.js";
|
||||
|
||||
// Route for API to get all items from the database
|
||||
@@ -79,4 +80,15 @@ router.post(
|
||||
}
|
||||
);
|
||||
|
||||
router.get("/open-door/:key/:doorKey", authenticate, async (req, res) => {
|
||||
const doorKey = req.params.doorKey;
|
||||
|
||||
const result = await openDoor(doorKey);
|
||||
if (result.success) {
|
||||
res.status(200).json({ data: result.data });
|
||||
} else {
|
||||
res.status(500).json({ message: "Failed to open door" });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user