added delete function to product table
This commit is contained in:
@@ -3,6 +3,7 @@ import dotenv from "dotenv";
|
||||
import { authenticate } from "../../services/tokenService.js";
|
||||
import {
|
||||
allProducts,
|
||||
deleteProduct,
|
||||
newProduct,
|
||||
productDetails,
|
||||
setAmount,
|
||||
@@ -147,4 +148,33 @@ router.post("/mutate/update-item", authenticate, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/delete-selection", authenticate, async (req, res) => {
|
||||
let isError = false;
|
||||
const uuidArray = req.body;
|
||||
|
||||
for (const uuid of uuidArray) {
|
||||
const response = await deleteProduct(uuid);
|
||||
if (response.code === "ep006" || !response) {
|
||||
isError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isError === false) {
|
||||
res.status(202).json({
|
||||
success: true,
|
||||
code: "sp006",
|
||||
data: null,
|
||||
message: "",
|
||||
});
|
||||
} else {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
code: "ep006",
|
||||
data: null,
|
||||
message: "",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user