added new api endpoint for getting the loan by the loan code
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
changeInSafeStateV2,
|
||||
setReturnDateV2,
|
||||
setTakeDateV2,
|
||||
getLoanByCodeV2,
|
||||
} from "../services/database.js";
|
||||
|
||||
dotenv.config();
|
||||
@@ -44,6 +45,19 @@ router.post("/controlInSafe/:key/:itemId/:state", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/getLoanByCode/:key/:loan_code", async (req, res) => {
|
||||
if (req.params.key === process.env.ADMIN_ID) {
|
||||
const loan_code = req.params.loan_code;
|
||||
|
||||
const result = await getLoanByCodeV2(loan_code);
|
||||
if (result.success) {
|
||||
res.status(200).json({ data: result.data });
|
||||
} else {
|
||||
res.status(404).json({ message: "Loan not found" });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Route for API to set the return date
|
||||
router.post("/setReturnDate/:key/:loan_code", async (req, res) => {
|
||||
if (req.params.key === process.env.ADMIN_ID) {
|
||||
|
@@ -28,6 +28,17 @@ export const getItemsFromDatabaseV2 = async () => {
|
||||
return { success: false };
|
||||
};
|
||||
|
||||
export const getLoanByCodeV2 = async (loan_code) => {
|
||||
const [result] = await pool.query(
|
||||
"SELECT * FROM loans WHERE loan_code = ?;",
|
||||
[loan_code]
|
||||
);
|
||||
if (result.length > 0) {
|
||||
return { success: true, data: result[0] };
|
||||
}
|
||||
return { success: false };
|
||||
};
|
||||
|
||||
export const changeInSafeStateV2 = async (itemId, state) => {
|
||||
const [result] = await pool.query(
|
||||
"UPDATE items SET inSafe = ? WHERE id = ?",
|
||||
|
Reference in New Issue
Block a user