Skip to content

Commit

Permalink
Merge pull request #99 from atlp-rwanda/fx-order-not
Browse files Browse the repository at this point in the history
fix : fixed undefined on order notifcation
  • Loading branch information
teerenzo authored Jul 30, 2024
2 parents 7f189f8 + 7fbfe30 commit ba8fd4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/controllers/wishesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { notificationEmitter } from "../utils/server";
import Notification from "../sequelize/models/Notification";
import { IUser } from "../types";
import Product from "../sequelize/models/products";
import { UserAttributes } from "../sequelize/models/users";

export const addToWishes = async (req: Request, res: Response) => {
//@ts-ignore
const id = req.user.id;
const currentUser: IUser = (req as any).user;
const currentUser = (req as any).user;
try {
const { error, value } = wishSchema.validate(req.body);
if (error) {
Expand All @@ -34,10 +35,16 @@ export const addToWishes = async (req: Request, res: Response) => {
if (wish) {
const notification = await Notification.create({
title: "Product Added to Wishlist",
message: `${currentUser.name} has added your product ${product.name} to his wishlist`,
message: `${currentUser?.dataValues?.name} has added your product ${product?.name} to his wishlist`,
userId: wish.sellerId,
});

if (currentUser) {
console.log("user who added product in wishlist", currentUser.dataValues);
} else {
console.log("no currentUser");
}

notificationEmitter.emit("wishlist", notification.dataValues);

return res.status(201).json({
Expand Down
6 changes: 5 additions & 1 deletion src/services/payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ export const placeOrder = async (cart: CartAttributes) => {
}
const notification = await Notification.create({
title: "Your have new order",
message: `${user?.username} has successfuly placed New Order on your product ${product?.name}`,
message: `${user?.dataValues.username} has successfuly placed New Order on your product ${product?.name}`,
userId: product?.userId,
});

if (user) {
console.log(user);
}

notificationEmitter.emit("new order", notification.dataValues);
}
const ordered = await Order.findOne({
Expand Down

0 comments on commit ba8fd4e

Please sign in to comment.