new feature: Error code 507 will return if you want to delete a loan that has not been returned
This commit is contained in:
@@ -84,6 +84,14 @@ export const MyLoansPage = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
|
if (res.status === 507) {
|
||||||
|
setMsgStatus("error");
|
||||||
|
setMsgTitle(t("error"));
|
||||||
|
setMsgDescription(t("error-deleting-loan-507"));
|
||||||
|
setIsMsg(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setMsgStatus("error");
|
setMsgStatus("error");
|
||||||
setMsgTitle(t("error"));
|
setMsgTitle(t("error"));
|
||||||
setMsgDescription(t("error-deleting-loan"));
|
setMsgDescription(t("error-deleting-loan"));
|
||||||
|
|||||||
@@ -93,5 +93,6 @@
|
|||||||
"try-naas": "Klick mich",
|
"try-naas": "Klick mich",
|
||||||
"naas-error": "Fehler mit no-as-a-service",
|
"naas-error": "Fehler mit no-as-a-service",
|
||||||
"naas-error-desc": "Ein Fehler ist beim Kommunizieren mit no-as-a-service aufgetreten.",
|
"naas-error-desc": "Ein Fehler ist beim Kommunizieren mit no-as-a-service aufgetreten.",
|
||||||
"naas-header": "Eine gute Möglichkeit, nein zu sagen..."
|
"naas-header": "Eine gute Möglichkeit, nein zu sagen...",
|
||||||
|
"error-deleting-loan-507": "Die Ausleihe kann nicht gelöscht werden, da sie noch nicht zurückgegeben wurde."
|
||||||
}
|
}
|
||||||
@@ -93,5 +93,6 @@
|
|||||||
"try-naas": "Click me",
|
"try-naas": "Click me",
|
||||||
"naas-error": "Error with no-as-a-service",
|
"naas-error": "Error with no-as-a-service",
|
||||||
"naas-error-desc": "An error occurred while communicating with no-as-a-service.",
|
"naas-error-desc": "An error occurred while communicating with no-as-a-service.",
|
||||||
"naas-header": "A good way to say no..."
|
"naas-header": "A good way to say no...",
|
||||||
|
"error-deleting-loan-507": "The loan cannot be deleted because it has not been returned yet."
|
||||||
}
|
}
|
||||||
@@ -234,6 +234,23 @@ export const getBorrowableItemsFromDatabase = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const SETdeleteLoanFromDatabase = async (loanId) => {
|
export const SETdeleteLoanFromDatabase = async (loanId) => {
|
||||||
|
const [checkIfdatesReturned] = await pool.query(
|
||||||
|
"SELECT take_date, returned_date FROM loans WHERE id = ? AND deleted = 0",
|
||||||
|
[loanId],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (checkIfdatesReturned.length === 0) {
|
||||||
|
return { success: false, code: "LOAN_NOT_FOUND" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const { take_date, returned_date } = checkIfdatesReturned[0];
|
||||||
|
const bothNull = take_date === null && returned_date === null;
|
||||||
|
const bothSet = take_date !== null && returned_date !== null;
|
||||||
|
|
||||||
|
if (!(bothNull || bothSet)) {
|
||||||
|
return { success: false, code: "LOAN_NOT_RETURNED" };
|
||||||
|
}
|
||||||
|
|
||||||
const [result] = await pool.query(
|
const [result] = await pool.query(
|
||||||
"UPDATE loans SET deleted = 1 WHERE id = ?;",
|
"UPDATE loans SET deleted = 1 WHERE id = ?;",
|
||||||
[loanId],
|
[loanId],
|
||||||
|
|||||||
@@ -134,6 +134,16 @@ router.delete("/delete-loan/:id", authenticate, async (req, res) => {
|
|||||||
if (result.success) {
|
if (result.success) {
|
||||||
res.status(200).json({ message: "Loan deleted successfully" });
|
res.status(200).json({ message: "Loan deleted successfully" });
|
||||||
} else {
|
} else {
|
||||||
|
if (result.code === "LOAN_NOT_FOUND") {
|
||||||
|
res.status(404).json({ message: "Loan not found" });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.code === "LOAN_NOT_RETURNED") {
|
||||||
|
res.status(507).json({
|
||||||
|
message: "Cannot delete loan that has not been returned",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
res.status(500).json({ message: "Failed to delete loan" });
|
res.status(500).json({ message: "Failed to delete loan" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ const app = express();
|
|||||||
const port = 8004;
|
const port = 8004;
|
||||||
const naasURL = process.env.NAAS_URL;
|
const naasURL = process.env.NAAS_URL;
|
||||||
|
|
||||||
console.log(naasURL);
|
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
// Body-Parser VOR den Routen registrieren
|
// Body-Parser VOR den Routen registrieren
|
||||||
app.use(express.json({ limit: "10mb" }));
|
app.use(express.json({ limit: "10mb" }));
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ This update provides some new features for the design. It also contains some imp
|
|||||||
## Improvements
|
## Improvements
|
||||||
|
|
||||||
- I have the error logging for the API route wehre you can take loans improved.
|
- I have the error logging for the API route wehre you can take loans improved.
|
||||||
|
- If you try to delete a loan that has not been returned yet, you will get an 507 error code.
|
||||||
|
|
||||||
## Fixed bugs
|
## Fixed bugs
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user