Skip to content

Commit

Permalink
Restored missing endpoint after rebase (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jadowacu1 authored Aug 6, 2024
1 parent 992abed commit d51c0c9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
35 changes: 23 additions & 12 deletions src/middlewares/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,18 +1007,29 @@ const isShopEmpty = async (req: Request, res: Response, next: NextFunction) => {
next();
}

const isOroderExistByShopId = async (req: Request, res: Response, next: NextFunction) => {
const shop = await productRepositories.findShopByUserId(req.user.id);
const orders = await productRepositories.sellerGetOrdersHistory(shop.id);

if (!orders) {
return res.status(httpStatus.NOT_FOUND).json({
status: httpStatus.NOT_FOUND,
error: "Order Not Found"
})
const isOrderExistByShopId = async (req: Request, res: Response, next: NextFunction) => {
try {
const shop = await productRepositories.findShopByUserId(req.user.id);
if(shop){
const orders = await productRepositories.sellerGetOrdersHistory(shop.id);
if (!orders) {
return res.status(httpStatus.NOT_FOUND).json({
status: httpStatus.NOT_FOUND,
error: "Order Not Found"
})
}
(req as any).ordersHistory = orders;
next();
}else{
return res.status(httpStatus.NOT_FOUND).json({
status: httpStatus.NOT_FOUND,
error: "No shop found"
})
}
} catch (error) {
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ status: httpStatus.INTERNAL_SERVER_ERROR, message: error.message })
}
(req as any).ordersHistory = orders;
next();

}

export {
Expand Down Expand Up @@ -1057,7 +1068,7 @@ export {
isOrderExist,
isOrderEmpty,
isShopEmpty,
isOroderExistByShopId,
isOrderExistByShopId,
isOrdersExist,
isOrderExists,
isOrderExists2
Expand Down
11 changes: 9 additions & 2 deletions src/modules/cart/controller/cartControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,13 @@ const userCreateOrder = (req, res) => {
}


const adminGetOrdersHistory = async(req: ExtendRequest, res:Response)=>{
const OrderHistory = (req as any).orders
return res.status(httpStatus.OK).json({
message: "Order History",
data: { OrderHistory }
})
}

export {
buyerGetCart,
Expand All @@ -445,6 +452,6 @@ export {
buyerUpdateCartStatus,
userCreateOrder,
buyerGetOrders2,
buyerGetOrderStatus2

buyerGetOrderStatus2,
adminGetOrdersHistory
};
2 changes: 1 addition & 1 deletion src/routes/cartRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ router.post("/create-stripe-product", userAuthorization(["buyer"]), validation(p
router.post("/checkout-stripe-session", userAuthorization(["buyer"]), validation(checkoutSessionSchema), stripeCheckoutSession);
router.post("/user-create-order",userAuthorization(["buyer"]), cartControllers.userCreateOrder)
router.put("/update-cart-status",userAuthorization(["buyer"]), cartControllers.buyerUpdateCartStatus)

router.get("/admin-get-order-history",userAuthorization(["admin"]),isOrderEmpty,cartControllers.adminGetOrdersHistory)
export default router;
5 changes: 2 additions & 3 deletions src/routes/productRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {
isProductExistIntoWishList,
isWishListProductExist,
isShopEmpty,
isOroderExistByShopId

isOrderExistByShopId
} from "../middlewares/validation";
import {
shopSchema,
Expand Down Expand Up @@ -125,5 +124,5 @@ router.post(
isProductOrdered,
productController.buyerReviewProduct )
router.get("/admin-get-shops",userAuthorization(["admin"]),isShopEmpty,productController.adminGetShops);
router.get("/seller-get-orderHistory",userAuthorization(["seller"]),isOroderExistByShopId,productController.sellerGetOrdersHistory);
router.get("/seller-get-orderHistory",userAuthorization(["seller"]),isOrderExistByShopId,productController.sellerGetOrdersHistory);
export default router;

0 comments on commit d51c0c9

Please sign in to comment.