Skip to content

Commit

Permalink
Ft buyer track order status #187584937 (#74)
Browse files Browse the repository at this point in the history
* The Seller and User -  list products (#58)

* Ft login v google 187584916 (#47)

* login via google

* Ft-login via google

* login via google

* ft login via google

* ft  login with  google

* Logout feature (#26) (#46)

* Logout feature (#26)

* [#187584914]added logout feature

* [starts #187584914] added logout feature

* [finishes#187584914] logout feature

* [delivers##187584914] updated readme & swagger.json

* [delivers##187584914] updated readme & swagger.json

* [deliveres #187584914] logout features completed

* [deliveres #187584914] logout features completed

* [delivers #187584914] finished logout feature

* fixing bugs

* rebased

---------

Co-authored-by: Solange Duhimbaze Ihirwe <[email protected]>

* [Finishes #187584924] Seller Create/Add a product (#48)

* [Delivers #187584924] Seller Create/Add a product

* updated ReaderMe file

* Rebased on develop

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Fixed login fetaure (#59)

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* Solve eerrors

* Ft delete items seller #187584926 (#52)

* rebase

* rebase

* [delivers #187584926] seller delete item

* [Delivers #187584924] Seller Create/Add a product

* [start #187584926] seller delete item

---------

Co-authored-by: Solangeihirwe <[email protected]>
Co-authored-by: AimePazzo <[email protected]>

* [Delivers #187584928] Delivers test 92.53%

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* Solve eerrors

* [Delivers #187584928] Delivers test 92.53%

* [Delivers #187584928] Delivers test 92.53%

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Add .gitguardian file

* [Delivers #187584928] Add .gitguardian file

* [starts #187584911] Seller statistics per timeframe (#54)

* [starts #187584911] Seller statistics per timeframe

* [finishes #187584911] Seller statistics per timeframe

* Seller-statistics updated

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* Solve eerrors

* [Delivers #187584928] Delivers test 92.53%

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [Delivers #187584928] Delivers test 92.53%

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Add .gitguardian file

* [Delivers #187584928] Add .gitguardian file

* AA

* pre commit tests

* Initial

* [Delivers #187584928] Version 1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* Solve eerrors

* [Delivers #187584928] Delivers test 92.53%

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [Delivers #187584928] Delivers test 92.53%

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Add .gitguardian file

* [Delivers #187584928] Add .gitguardian file

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* Solve eerrors

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [Delivers #187584928] Delivers test 92.53%

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* AA

* pre commit tests

* Initial

* [Delivers #187584928] Version 1

* Swagger

* Rebase

* Reviews

* M

* end

* end

* end

* end

---------

Co-authored-by: AimePazzo <[email protected]>
Co-authored-by: Niyonshuti Jean De Dieu <[email protected]>
Co-authored-by: MANISHIMWESalton <[email protected]>
Co-authored-by: Solange Duhimbaze Ihirwe <[email protected]>
Co-authored-by: Mr. David <[email protected]>
Co-authored-by: Solangeihirwe <[email protected]>
Co-authored-by: SaddockAime <[email protected]>

* [start #187584937] buyer track order status

* [finishes #187584937] buyer track order status

* The Seller and User -  list products (#58)

* Ft login v google 187584916 (#47)

* login via google

* Ft-login via google

* login via google

* ft login via google

* ft  login with  google

* Logout feature (#26) (#46)

* Logout feature (#26)

* [#187584914]added logout feature

* [starts #187584914] added logout feature

* [finishes#187584914] logout feature

* [delivers##187584914] updated readme & swagger.json

* [delivers##187584914] updated readme & swagger.json

* [deliveres #187584914] logout features completed

* [deliveres #187584914] logout features completed

* [delivers #187584914] finished logout feature

* fixing bugs

* rebased

---------

Co-authored-by: Solange Duhimbaze Ihirwe <[email protected]>

* [Finishes #187584924] Seller Create/Add a product (#48)

* [Delivers #187584924] Seller Create/Add a product

* updated ReaderMe file

* Rebased on develop

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Fixed login fetaure (#59)

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* Solve eerrors

* Ft delete items seller #187584926 (#52)

* rebase

* rebase

* [delivers #187584926] seller delete item

* [Delivers #187584924] Seller Create/Add a product

* [start #187584926] seller delete item

---------

Co-authored-by: Solangeihirwe <[email protected]>
Co-authored-by: AimePazzo <[email protected]>

* [Delivers #187584928] Delivers test 92.53%

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* Solve eerrors

* [Delivers #187584928] Delivers test 92.53%

* [Delivers #187584928] Delivers test 92.53%

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Add .gitguardian file

* [Delivers #187584928] Add .gitguardian file

* [starts #187584911] Seller statistics per timeframe (#54)

* [starts #187584911] Seller statistics per timeframe

* [finishes #187584911] Seller statistics per timeframe

* Seller-statistics updated

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* Solve eerrors

* [Delivers #187584928] Delivers test 92.53%

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [Delivers #187584928] Delivers test 92.53%

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Add .gitguardian file

* [Delivers #187584928] Add .gitguardian file

* AA

* pre commit tests

* Initial

* [Delivers #187584928] Version 1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* Solve eerrors

* [Delivers #187584928] Delivers test 92.53%

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [Delivers #187584928] Delivers test 92.53%

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Add .gitguardian file

* [Delivers #187584928] Add .gitguardian file

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* Solve eerrors

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [delivers #187584928] Delivers the Seller and User list products

* [delivers #187584928] Delivers the Seller and User list products

* [Delivers #ft-seller-and-buyer-list-items-187584928] Tests version 1

* Deliver testing v1

* [Delivers #187584928] Delivers test 92.53%

* [Delivers #187584928] Handle gitguardian issues.

* [Delivers #187584928] Handle gitguardian issues.

* AA

* pre commit tests

* Initial

* [Delivers #187584928] Version 1

* Swagger

* Rebase

* Reviews

* M

* end

* end

* end

* end

---------

Co-authored-by: AimePazzo <[email protected]>
Co-authored-by: Niyonshuti Jean De Dieu <[email protected]>
Co-authored-by: MANISHIMWESalton <[email protected]>
Co-authored-by: Solange Duhimbaze Ihirwe <[email protected]>
Co-authored-by: Mr. David <[email protected]>
Co-authored-by: Solangeihirwe <[email protected]>
Co-authored-by: SaddockAime <[email protected]>

* [start #187584937] buyer track order status

* [finishes #187584937] buyer track order status

* [deliver #187584937] buyer track order status

* [deliver #187584937] buyer track order status

---------

Co-authored-by: Ndahimana Bonheur <[email protected]>
Co-authored-by: AimePazzo <[email protected]>
Co-authored-by: Niyonshuti Jean De Dieu <[email protected]>
Co-authored-by: MANISHIMWESalton <[email protected]>
Co-authored-by: Mr. David <[email protected]>
Co-authored-by: Solangeihirwe <[email protected]>
Co-authored-by: SaddockAime <[email protected]>
  • Loading branch information
8 people authored Jul 16, 2024
1 parent 938c14d commit eb92726
Show file tree
Hide file tree
Showing 19 changed files with 1,010 additions and 148 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ Our e-commerce web application server, developed by Team Ninjas, facilitates smo
- User mark notification Endpoint
- Buyer review product Endpoint
- Submit a seller request
- Buyer track order status Endpoint
- Admin update order status EndPoint
- Buyer get order history Endpoint

## TABLE OF API ENDPOINTS SPECIFICATION AND DESCRIPTION

Expand Down Expand Up @@ -120,6 +123,10 @@ Our e-commerce web application server, developed by Team Ninjas, facilitates smo
| 44 | PUT | /api/user/user-mark-notification/:id | 200 OK | private | user mark notification |
| 45 | POST | /api/shop/buyer-review-product/:id | 200 OK | private | Buyer Create review |
| 46 | POST | /api/user/user-submit-seller-request | 200 OK | private | Submit a seller request |
| 47 | GET | /api/cart/user-get-order-status/:id | 200 OK | private | user get order status |
| 48 | GET | /api/cart/buyer-get-order-history | 200 OK | private | buyer get order history |
| 49 | PUT | /api/cart/admin-update-order-status/:id | 200 OK | private | admin update order status |


## INSTALLATION

Expand Down Expand Up @@ -188,12 +195,4 @@ Our e-commerce web application server, developed by Team Ninjas, facilitates smo
7. Run the Migration:
```sh
npm run createAllTables
```
8. Delete the Seeder:
```sh
npm run deleteAllSeeders
```
9. Delete the Migration:
```sh
npm run deleteAllTables
```
24 changes: 1 addition & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"src/services/stripe.ts",
"src/services/cronJob.ts",
"src/helpers/passwordExpiryNotifications.ts"

],
"reporter": [
"html",
Expand Down Expand Up @@ -111,8 +110,7 @@
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"typescript": "^5.4.5",
"uuid": "^9.0.1",
"ws": "^8.17.0"
"uuid": "^9.0.1"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",
Expand Down
8 changes: 8 additions & 0 deletions src/databases/migrations/20240604150804-create-orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ export = {
type: DataTypes.STRING,
allowNull: false
},
shippingProcess: {
type: DataTypes.STRING,
allowNull: false
},
expectedDeliveryDate:{
type:DataTypes.DATE,
allowNull: false
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
Expand Down
2 changes: 1 addition & 1 deletion src/databases/models/carts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Carts extends Model<CartAttributes> implements CartAttributes {
static associate() {
Carts.belongsTo(Users, { foreignKey: "userId", as: "buyer" });
Carts.hasMany(CartProducts, { foreignKey: "cartId", as: "cartProducts" });
Carts.hasMany(Orders,{foreignKey: "cartId", as: "order"})
Carts.hasMany(Orders,{foreignKey: "cartId", as: "orders"})
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/databases/models/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface OrderAttributes {
paymentMethodId: string;
orderDate: Date;
status: string;
shippingProcess: string;
expectedDeliveryDate: Date
createdAt: Date;
updatedAt: Date;
}
Expand All @@ -26,6 +28,8 @@ class Orders extends Model<OrderAttributes> implements OrderAttributes {
declare paymentMethodId: string;
declare orderDate: Date;
declare status: string;
declare shippingProcess: string;
declare expectedDeliveryDate: Date;
declare createdAt: Date;
declare updatedAt: Date;

Expand Down Expand Up @@ -68,6 +72,14 @@ Orders.init(
type: new DataTypes.STRING,
allowNull: false
},
shippingProcess: {
type: DataTypes.STRING,
allowNull: false
},
expectedDeliveryDate:{
type:DataTypes.DATE,
allowNull: false
},
createdAt: {
field: "createdAt",
type: DataTypes.DATE,
Expand Down
4 changes: 4 additions & 0 deletions src/databases/seeders/20240604133044-orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module.exports = {
paymentMethodId: 1,
orderDate: new Date("2024-01-01"),
status: "completed",
shippingProcess : "your order have been completed",
expectedDeliveryDate: new Date("2024-08-01"),
createdAt: new Date(),
updatedAt: new Date()
},
Expand All @@ -42,6 +44,8 @@ module.exports = {
paymentMethodId: 2,
orderDate: new Date("2024-01-15"),
status: "completed",
shippingProcess : "your order have reached Kigali in 30 minutes it will be reached to you",
expectedDeliveryDate: new Date("2024-08-05"),
createdAt: new Date(),
updatedAt: new Date()
}
Expand Down
22 changes: 20 additions & 2 deletions src/helpers/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { sendEmailNotification } from "../services/sendEmail";
import { sendEmailNotification, sendEmailOrderStatus } from "../services/sendEmail";
import userRepositories from "../modules/user/repository/userRepositories";
import { EventEmitter } from "events";
import cron from "node-cron";
import productRepository from "../modules/product/repositories/productRepositories";
import Products from "../databases/models/products";
import Shops from "../databases/models/shops";
import Users from "../databases/models/users";
import { IProductsWithShop } from "../types/index";
import { IProductsWithShop, IOrderWithCart } from "../types/index";
import { io } from "../index";
import Orders from "../databases/models/orders";
import Carts from "../databases/models/carts";

export const eventEmitter = new EventEmitter();

Expand All @@ -24,6 +26,13 @@ const saveAndEmitNotification = async (userId: string, message: string, event: s
await sendEmailNotification(userId, message);
};

const fetchOrderWithCarts = async (orderId: string): Promise<IOrderWithCart> => {
return (await Orders.findOne({
where: { id: orderId },
include: { model: Carts, as: "carts" }
})) as IOrderWithCart;
};

eventEmitter.on("productAdded", async (product) => {
const productWithShop = await fetchProductWithShop(product.id);
const userId = productWithShop.shops.userId;
Expand Down Expand Up @@ -74,6 +83,15 @@ eventEmitter.on("passwordExpiry", async ({ userId, message }) => {
await saveAndEmitNotification(userId, message, "passwordExpiry");
});

eventEmitter.on("orderStatusUpdated", async (order) => {
const orderStatus = await fetchOrderWithCarts(order.id)
const userId = orderStatus.carts.userId
const message = order.shippingProcess;
await userRepositories.addNotification(userId, message);
await sendEmailOrderStatus(userId, message);
io.to(userId).emit("orderStatusUpdated", message)
});

cron.schedule("0 0 * * *", async () => {
const users = await Users.findAll();
for (const user of users) {
Expand Down
49 changes: 47 additions & 2 deletions src/middlewares/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,50 @@ const isSellerRequestExist = async (req: Request, res: Response, next: NextFunct
}
};

const isOrderExist = async (req: Request, res:Response, next:NextFunction)=>{
try{
let order: any;
if (req.user.role === "buyer") {
if(req.params.id){
order = await cartRepositories.getOrderByOrderIdAndUserId(req.params.id, req.user.id)
if(!order){
return res.status(httpStatus.NOT_FOUND).json({
status: httpStatus.NOT_FOUND,
error: "order not found"
})
}
}else{
order = await cartRepositories.getOrdersByUserId(req.user.id)
if(!order.orders || order.orders.length === 0){
return res.status(httpStatus.NOT_FOUND).json({
status: httpStatus.NOT_FOUND,
error: "orders not found"
})
}
}

}
if(req.user.role === "admin"){
order = await cartRepositories.getOrderById(req.params.id)
if (!order) {
return res.status(httpStatus.NOT_FOUND).json({
status: httpStatus.NOT_FOUND,
error: "order Not Found",
});
}
}
(req as any).order = order
return next();
}
catch(error){
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
status: httpStatus.INTERNAL_SERVER_ERROR,
error: error.message
})
}
}


export {
validation,
isUserExist,
Expand Down Expand Up @@ -924,5 +968,6 @@ export {
isProductExistIntoWishList,
isProductOrdered,
isUserProfileComplete,
isSellerRequestExist
};
isSellerRequestExist,
isOrderExist
};
53 changes: 53 additions & 0 deletions src/modules/cart/controller/cartControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,56 @@ const paymentCanceled = (req: Request, res: Response) => {
}
};

const buyerGetOrderStatus = async (req: ExtendRequest, res: Response) => {
try {
const order = req.order.shippingProcess
return res.status(httpStatus.OK).json({
message: "Order Status found successfully",
data: {order}
})

} catch (error) {
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
status: httpStatus.INTERNAL_SERVER_ERROR,
error: error.message
})
}
}

const buyerGetOrders = async(req:ExtendRequest, res:Response)=>{
try{
const orders = req.order
return res.status(httpStatus.OK).json({
message: "Orders found successfully",
data: {orders}
})
}
catch(error){
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
status: httpStatus.INTERNAL_SERVER_ERROR,
error: error.message
})
}
}

const adminUpdateOrderStatus = async (req: ExtendRequest, res: Response) => {
try {
const order = req.order
await cartRepositories.updateOrderStatus(req.params.id, req.body.status,req.body.shippingProcess);
eventEmitter.emit("orderStatusUpdated", order);
return res.status(httpStatus.OK).json({
message: "Status updated successfully!",
data: { order }
})
}catch(error){
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
status: httpStatus.INTERNAL_SERVER_ERROR,
error: error.message
})
}

}

export {
buyerGetCart,
buyerGetCarts,
Expand All @@ -363,4 +413,7 @@ export {
paymentSuccess,
paymentCanceled,
addProductToExistingCart,
buyerGetOrderStatus,
buyerGetOrders,
adminUpdateOrderStatus
};
Loading

0 comments on commit eb92726

Please sign in to comment.