Skip to content

Commit

Permalink
Merge pull request #96 from atlp-rwanda/fx-nots
Browse files Browse the repository at this point in the history
Fix: fixed undefined notification when product deleted
  • Loading branch information
teerenzo authored Jul 24, 2024
2 parents 07072e9 + 93634da commit 2e4abc4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/controllers/productControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { updateProductTemplate } from "../email-templates/updated";
import { createdProductTemplate } from "../email-templates/created";
import { createReview, deleteReview, getProductReviews, updateReview } from "../services/product.service";
import Review from "../sequelize/models/reviews";
import Product from "../sequelize/models/products";

export const fetchProducts = async (req: Request, res: Response) => {
try {
Expand Down Expand Up @@ -162,18 +163,20 @@ export const productsUpdate = async (req: Request, res: Response) => {

export const removeProducts = async (req: Request, res: Response) => {
const currentUser: UserAttributes = (req as any).user;
const id = req.params.id;
try {
const isDeleted = await deleteProduct(req, res);
if (isDeleted) {
const loggedInUser: any = req.user;
const product = await Product.findOne({ where: { id, userId: loggedInUser.id } });
//@ts-ignore
await mailService.sendNotification(currentUser.email, "Product deleted", removedProductTemplate(currentUser.username, isDeleted?.name));
await mailService.sendNotification(currentUser.email, "Product deleted", removedProductTemplate(currentUser.username, product?.name));

const notification = await Notification.create({
title: "Product Deleted",
//@ts-ignore
message: `Your Product ${isDeleted.name} successfully deleted`,
//@ts-ignore
userId: currentUser.id || undefined,

message: `Your Product ${product?.name} successfully deleted`,
userId: currentUser.id as number,
});

notificationEmitter.emit("deleted", notification.dataValues);
Expand Down

0 comments on commit 2e4abc4

Please sign in to comment.