added changeSafeState function
This commit is contained in:
@@ -319,9 +319,9 @@ router.post("/updateItemByID", authenticate, async (req, res) => {
|
||||
return res.status(500).json({ message: "Failed to update item" });
|
||||
});
|
||||
|
||||
router.post("/setSafeState", authenticate, async (req, res) => {
|
||||
const { itemId, state } = req.body || {};
|
||||
const result = await changeInSafeStateV2(itemId, state);
|
||||
router.put("/changeSafeState/:itemId", authenticate, async (req, res) => {
|
||||
const itemId = req.params.itemId;
|
||||
const result = await changeInSafeStateV2(itemId);
|
||||
if (result.success) {
|
||||
return res
|
||||
.status(200)
|
||||
|
@@ -39,10 +39,10 @@ export const getLoanByCodeV2 = async (loan_code) => {
|
||||
return { success: false };
|
||||
};
|
||||
|
||||
export const changeInSafeStateV2 = async (itemId, state) => {
|
||||
export const changeInSafeStateV2 = async (itemId) => {
|
||||
const [result] = await pool.query(
|
||||
"UPDATE items SET inSafe = ? WHERE id = ?",
|
||||
[state, itemId]
|
||||
"UPDATE items SET inSafe = NOT inSafe WHERE id = ?",
|
||||
[itemId]
|
||||
);
|
||||
if (result.affectedRows > 0) {
|
||||
return { success: true };
|
||||
|
Reference in New Issue
Block a user