Skip to content
Snippets Groups Projects
Commit ea42339d authored by Povilas Lajus's avatar Povilas Lajus
Browse files

feat: add order update

parent 67a3d859
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ const validate = (req: Request, res: Response, next: NextFunction) => {
export const validateProductOperation = [
param("id").exists().trim(),
body("productId").exists(),
body("amount").optional().isNumeric(),
validate,
];
......
......@@ -4,7 +4,7 @@ import OrdersController from "../controllers/orders.controller";
import {
validateFindById,
validateNewOrder,
validateUpdateOrderStatus,
validateUpdateOrder,
} from "../services/orderValidator";
export const router = express.Router();
......@@ -19,4 +19,6 @@ router.get("/:id", validateFindById, orders.getOrder);
router.post("/", validateNewOrder, orders.createOrder);
router.put("/status/update", validateUpdateOrderStatus, orders.updateStatus);
router.put("/:id", validateUpdateOrder, orders.updateOrder);
router.delete("/:id", validateFindById, orders.deleteOrder);
......@@ -13,10 +13,10 @@ export const validateNewOrder = [
body("status")
.optional()
.isIn(["New", "Pending", "Hold", "Shipped", "Delivered"]),
body("total").exists().isNumeric(),
body("total").exists().isString(),
body("addressId").exists().not().isEmpty(),
body("paymentId").exists().not().isEmpty(),
body("addressId").exists().not().isEmpty().isNumeric(),
body("paymentId").exists().not().isEmpty().isNumeric(),
body("orderItems").exists().isArray(),
body("orderItems.*.productId").exists().isString(),
......@@ -24,11 +24,28 @@ export const validateNewOrder = [
validate,
];
export const validateUpdateOrderStatus = [
// export const validateUpdateOrderStatus = [
// param("id").exists(),
// body("newStatus")
// .exists()
// .isIn(["New", "Pending", "Hold", "Shipped", "Delivered"]),
// validate,
// ];
export const validateUpdateOrder = [
param("id").exists(),
body("newStatus")
oneOf([
body("status")
.exists()
.isIn(["New", "Pending", "Hold", "Shipped", "Delivered"]),
body("addressId").exists().not().isEmpty().isNumeric(),
body("paymentId").exists().not().isEmpty().isNumeric(),
]),
body("customerEmail").not().exists(),
body("total").not().exists(),
body("orderItems").not().exists(),
validate,
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment