From 69b081808c230a71f09cedc99964bd81d603cd6a Mon Sep 17 00:00:00 2001 From: "Gisa M. Caleb Pacifique" Date: Sun, 21 Jul 2024 16:50:35 +0200 Subject: [PATCH] Fix-Notification-links --- src/entities/NotificationItem.ts | 2 +- src/services/adminOrderServices/readOrder.ts | 8 +++---- .../adminOrderServices/updateOrder.ts | 21 ++++++++++++++++--- .../couponServices/buyerApplyCoupon.ts | 3 +-- .../feedbackServices/createFeedback.ts | 2 +- src/services/orderServices/createOrder.ts | 2 +- .../orderServices/updateOrderService.ts | 4 ++-- .../vendorOrderServices/readVendorOrder.ts | 2 +- 8 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/entities/NotificationItem.ts b/src/entities/NotificationItem.ts index df5881a..25b9d94 100644 --- a/src/entities/NotificationItem.ts +++ b/src/entities/NotificationItem.ts @@ -29,7 +29,7 @@ export class NotificationItem{ 'cart', 'order', 'user', - 'wish list', + 'wishlist', 'coupon', ]) type!: string diff --git a/src/services/adminOrderServices/readOrder.ts b/src/services/adminOrderServices/readOrder.ts index 4bb20f0..45a5f97 100644 --- a/src/services/adminOrderServices/readOrder.ts +++ b/src/services/adminOrderServices/readOrder.ts @@ -48,7 +48,7 @@ export const getBuyerVendorOrdersService = async (req: Request, res: Response) = id: order.buyer.id, firstName: order.buyer.firstName, lastName: order.buyer.lastName, - email: order.buyer.lastName, + email: order.buyer.email, gender: order.buyer.gender, phoneNumber: order.buyer.phoneNumber, photoUrl: order.buyer.photoUrl, @@ -57,7 +57,7 @@ export const getBuyerVendorOrdersService = async (req: Request, res: Response) = id: vendoOrder.vendor.id, firstName: vendoOrder.vendor.firstName, lastName: vendoOrder.vendor.lastName, - email: vendoOrder.vendor.lastName, + email: vendoOrder.vendor.email, gender: vendoOrder.vendor.gender, phoneNumber: vendoOrder.vendor.phoneNumber, photoUrl: vendoOrder.vendor.photoUrl, @@ -125,7 +125,7 @@ export const getSingleBuyerVendorOrderService = async (req: Request, res: Respon id: order.buyer.id, firstName: order.buyer.firstName, lastName: order.buyer.lastName, - email: order.buyer.lastName, + email: order.buyer.email, gender: order.buyer.gender, phoneNumber: order.buyer.phoneNumber, photoUrl: order.buyer.photoUrl, @@ -134,7 +134,7 @@ export const getSingleBuyerVendorOrderService = async (req: Request, res: Respon id: vendoOrder.vendor.id, firstName: vendoOrder.vendor.firstName, lastName: vendoOrder.vendor.lastName, - email: vendoOrder.vendor.lastName, + email: vendoOrder.vendor.email, gender: vendoOrder.vendor.gender, phoneNumber: vendoOrder.vendor.phoneNumber, photoUrl: vendoOrder.vendor.photoUrl, diff --git a/src/services/adminOrderServices/updateOrder.ts b/src/services/adminOrderServices/updateOrder.ts index 876160f..6de4e92 100644 --- a/src/services/adminOrderServices/updateOrder.ts +++ b/src/services/adminOrderServices/updateOrder.ts @@ -5,6 +5,7 @@ import { VendorOrderItem } from '../../entities/VendorOrderItem'; import { VendorOrders } from '../../entities/vendorOrders'; import { Order } from '../../entities/Order'; import { getIO } from '../../utils/socket'; +import { sendNotification } from '../../utils/sendNotification'; export const updateBuyerVendorOrderService = async (req: Request, res: Response) => { try { @@ -52,9 +53,23 @@ export const updateBuyerVendorOrderService = async (req: Request, res: Response) order.orderStatus = 'completed'; await orderRepository.save(order); - const updatedVendorOrder = vendorOrders.map(async order => { - order.orderStatus = 'completed'; - await vendorOrderRepository.save(order); + await sendNotification({ + content: 'Your order was marked completed', + type: 'order', + user: order.buyer, + link: `/orders/${order.id}`, + }); + + const updatedVendorOrder = vendorOrders.map(async vendorOrder => { + vendorOrder.orderStatus = 'completed'; + await vendorOrderRepository.save(vendorOrder); + + await sendNotification({ + content: `Order from buyer "${order.buyer.firstName} ${order.buyer.lastName}" has been marked completed`, + type: 'order', + user: vendorOrder.vendor, + link: `/vendor/dashboard/orders/${order.id}`, + }); }); const sanitizedOrderResponse = { diff --git a/src/services/couponServices/buyerApplyCoupon.ts b/src/services/couponServices/buyerApplyCoupon.ts index 93fa208..85b2517 100644 --- a/src/services/couponServices/buyerApplyCoupon.ts +++ b/src/services/couponServices/buyerApplyCoupon.ts @@ -85,8 +85,7 @@ export const buyerApplyCouponService = async (req: Request, res: Response) => { await sendNotification({ content: `Buyer: "${cart?.user.firstName} ${cart?.user.lastName}" used coupon and got discount on product: "${couponCartItem.product.name}"`, type:'coupon', - user: coupon.vendor, - link: `/coupons/vendor/${coupon.vendor.id}/checkout/${couponCode}` + user: coupon.vendor }); return res diff --git a/src/services/feedbackServices/createFeedback.ts b/src/services/feedbackServices/createFeedback.ts index 8956bb7..da561e9 100644 --- a/src/services/feedbackServices/createFeedback.ts +++ b/src/services/feedbackServices/createFeedback.ts @@ -42,7 +42,7 @@ export const createFeedbackService = async (req: Request, res: Response) => { content: `Buyer: "${order.buyer.firstName} ${order.buyer.lastName}" sent feedback on product: ${product.name}`, type: "product", user: product.vendor, - link: `/product/collection/${product.id}` + link: `/vendor/dashboard/products/${product.id}` }) return responseSuccess(res, 201, 'Feedback created successfully', feedback); diff --git a/src/services/orderServices/createOrder.ts b/src/services/orderServices/createOrder.ts index 1798e16..29e5504 100644 --- a/src/services/orderServices/createOrder.ts +++ b/src/services/orderServices/createOrder.ts @@ -181,7 +181,7 @@ const saveVendorRelatedOrder = async (order: Order, CartItem: CartItem[]) => { content: `Buyer "${vendorOrders.order.buyer.firstName} ${vendorOrders.order.buyer.lastName}" has added one of your products to their order. Please confirm that you'll be able to deliver it.`, type: 'order', user: vendorOrders.vendor, - link: `/product/vendor/orders/${vendorOrders.id}` + link: `/vendor/dashboard/orders/${vendorOrders.id}` }); } } diff --git a/src/services/orderServices/updateOrderService.ts b/src/services/orderServices/updateOrderService.ts index 23b7662..132870c 100644 --- a/src/services/orderServices/updateOrderService.ts +++ b/src/services/orderServices/updateOrderService.ts @@ -78,7 +78,7 @@ export const updateOrderService = async (req: Request, res: Response) => { content: `The Buyer named "${order.buyer.firstName} ${order.buyer.lastName}", has confirmed that they have successfully received their order.`, type: 'order', user: admin, - link: `/product/admin/orders/${order.id}` + link: `/admin/dashboard/products/${order.id}` }); }); } @@ -99,7 +99,7 @@ export const updateOrderService = async (req: Request, res: Response) => { content: `The Buyer named "${order.buyer.firstName} ${order.buyer.lastName}", has marked their order as "${orderStatus}". Please ensure that you update the order status on your side as well.`, type: 'order', user: vendorOrder.vendor, - link: `/product/vendor/orders/${vendorOrder.id}` + link: `/vendor/dashboard/orders/${vendorOrder.id}` }); }); diff --git a/src/services/vendorOrderServices/readVendorOrder.ts b/src/services/vendorOrderServices/readVendorOrder.ts index 9671608..2769602 100644 --- a/src/services/vendorOrderServices/readVendorOrder.ts +++ b/src/services/vendorOrderServices/readVendorOrder.ts @@ -45,7 +45,7 @@ export const getVendorOrdersService = async (req: Request, res: Response) => { id: order.order.buyer.id, firstName: order.order.buyer.firstName, lastName: order.order.buyer.lastName, - email: order.order.buyer.lastName, + email: order.order.buyer.email, gender: order.order.buyer.gender, phoneNumber: order.order.buyer.phoneNumber, photoUrl: order.order.buyer.photoUrl,