Skip to content

Commit

Permalink
Merge pull request #126 from atlp-rwanda/fix-notification-links
Browse files Browse the repository at this point in the history
Fix-Notification-links
  • Loading branch information
faid-terence authored Jul 21, 2024
2 parents d33ca3a + 69b0818 commit 4cefa3a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/entities/NotificationItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class NotificationItem{
'cart',
'order',
'user',
'wish list',
'wishlist',
'coupon',
])
type!: string
Expand Down
8 changes: 4 additions & 4 deletions src/services/adminOrderServices/readOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
21 changes: 18 additions & 3 deletions src/services/adminOrderServices/updateOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = {
Expand Down
3 changes: 1 addition & 2 deletions src/services/couponServices/buyerApplyCoupon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/services/feedbackServices/createFeedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/services/orderServices/createOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/orderServices/updateOrderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
});
});
}
Expand All @@ -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}`
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/services/vendorOrderServices/readVendorOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 4cefa3a

Please sign in to comment.