diff --git a/package-lock.json b/package-lock.json
index dcdfcb3..54900d4 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -52,6 +52,7 @@
"@types/jsonwebtoken": "^9.0.6",
"@types/mailgun-js": "^0.22.18",
"@types/morgan": "^1.9.9",
+ "@types/node-cron": "^3.0.11",
"@types/node-fetch": "^2.6.11",
"@types/nodemailer": "^6.4.15",
"@types/passport": "^1.0.16",
@@ -1882,6 +1883,12 @@
"undici-types": "~5.26.4"
}
},
+ "node_modules/@types/node-cron": {
+ "version": "3.0.11",
+ "resolved": "https://registry.npmjs.org/@types/node-cron/-/node-cron-3.0.11.tgz",
+ "integrity": "sha512-0ikrnug3/IyneSHqCBeslAhlK2aBfYek1fGo4bP4QnZPmiqSGRK+Oy7ZMisLWkesffJvQ1cqAcBnJC+8+nxIAg==",
+ "dev": true
+ },
"node_modules/@types/node-fetch": {
"version": "2.6.11",
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz",
@@ -7228,6 +7235,27 @@
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-5.1.0.tgz",
"integrity": "sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA=="
},
+ "node_modules/node-cron": {
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/node-cron/-/node-cron-3.0.3.tgz",
+ "integrity": "sha512-dOal67//nohNgYWb+nWmg5dkFdIwDm8EpeGYMekPMrngV3637lqnX0lbUcCtgibHTz6SEz7DAIjKvKDFYCnO1A==",
+ "dev": true,
+ "dependencies": {
+ "uuid": "8.3.2"
+ },
+ "engines": {
+ "node": ">=6.0.0"
+ }
+ },
+ "node_modules/node-cron/node_modules/uuid": {
+ "version": "8.3.2",
+ "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
+ "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
+ "dev": true,
+ "bin": {
+ "uuid": "dist/bin/uuid"
+ }
+ },
"node_modules/node-fetch": {
"version": "2.6.7",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
diff --git a/package.json b/package.json
index d0c33f0..9e2a566 100644
--- a/package.json
+++ b/package.json
@@ -43,7 +43,6 @@
"mailgun-js": "^0.22.0",
"morgan": "^1.10.0",
"node-fetch": "^2.6.7",
- "node-fetch": "^2.6.7",
"nodemailer": "^6.9.13",
"nodemon": "^3.1.0",
"otplib": "^12.0.1",
diff --git a/src/Notification.vendor/EmailSendor.ts b/src/Notification.vendor/EmailSendor.ts
index c0abe70..4a536e0 100644
--- a/src/Notification.vendor/EmailSendor.ts
+++ b/src/Notification.vendor/EmailSendor.ts
@@ -3,30 +3,29 @@ import dotenv from 'dotenv';
dotenv.config();
-async function sendEmail(vendorEmail: string, message_title:string, messageContent: string) {
-
- const transporter = nodemailer.createTransport({
- service:'gmail',
- host: "smtp.gmail.com",
- port: 587,
- secure: false,
- auth: {
+async function sendEmail(vendorEmail: string, message_title: string, messageContent: string) {
+ try {
+ const transporter = nodemailer.createTransport({
+ service: 'gmail',
+ host: 'smtp.gmail.com',
+ port: 587,
+ secure: false,
+ auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
- },
- });
+ },
+ });
- const mailOptions = {
- from: `"The E-commerce Team" <${process.env.EMAIL_USER}>`,
- to: "ericniyibizi1998@gmail.com",
- subject: 'Notification from Your Company',
- text: messageContent,
- html: `
${messageContent.replace(/\n/g, '
')}
`,
- };
+ const mailOptions = {
+ from: `"The E-commerce Team" <${process.env.EMAIL_USER}>`,
+ to: vendorEmail,
+ subject: message_title,
+ text: messageContent,
+ html: `${messageContent.replace(/\n/g, '
')}
`,
+ };
- try {
- const info = await transporter.sendMail(mailOptions);
- console.log('Message sent: %s', vendorEmail);
+ await transporter.sendMail(mailOptions);
+ console.log('Email sent successfully');
} catch (error) {
console.error('Error sending email:', error);
}
diff --git a/src/Notification.vendor/event.services.ts b/src/Notification.vendor/event.services.ts
index c0c90bb..ec2b991 100644
--- a/src/Notification.vendor/event.services.ts
+++ b/src/Notification.vendor/event.services.ts
@@ -2,7 +2,6 @@ import { EventEmitter } from 'events';
import Notification_box from '../database/models/inbox_notification';
import UserModel from '../database/models/userModel';
import Product from '../database/models/productEntity';
-import { Cart } from '../database/models/cartEntity';
import { Order } from '../database/models/orderEntity';
import dbConnection from '../database';
import sendEmailfunc from './EmailSendor';
@@ -15,26 +14,8 @@ import {
updated_Product,
product_deleted} from './message.Templete';
-import { number } from 'joi';
-
export const eventEmitter = new EventEmitter();
-interface cart {
- id: number;
- user: UserModel;
- product: Product;
- quantity: number;
- createdAt: Date;
- updatedAt: Date;
-}
-
-interface userModel {
- id: number;
- firstName: string;
- lastName: string;
- email: string;
- picture: string | null;
-}
interface product {
id: number;
@@ -79,12 +60,10 @@ interface OrderDetails {
const productRepository = dbConnection.getRepository(Product);
const userRepository = dbConnection.getRepository(UserModel);
const NotificationRepository = dbConnection.getRepository(Notification_box);
-const cartRepository = dbConnection.getRepository(Cart);
const orderRepository = dbConnection.getRepository(Order);
eventEmitter.on('addToCart', async (product_id, userId) => {
try {
- console.log('the event is listed');
const product = await productRepository.findOne({
where: { id: product_id },
select: { vendor: { firstName: true, lastName: true, picture: true, id: true, email: true } },
diff --git a/src/Notification.vendor/message.Templete.ts b/src/Notification.vendor/message.Templete.ts
index 3748b6e..32f5eeb 100644
--- a/src/Notification.vendor/message.Templete.ts
+++ b/src/Notification.vendor/message.Templete.ts
@@ -1,5 +1,3 @@
-import { string } from "joi";
-
interface UserModel {
id: number;
firstName: string;
diff --git a/src/Notification.vendor/node.cron.services.ts b/src/Notification.vendor/node.cron.services.ts
index 63f9972..d9c4ab0 100644
--- a/src/Notification.vendor/node.cron.services.ts
+++ b/src/Notification.vendor/node.cron.services.ts
@@ -1,81 +1,18 @@
import { EventEmitter } from 'events';
import Notification_box from '../database/models/inbox_notification';
-import UserModel from '../database/models/userModel';
import Product from '../database/models/productEntity';
-import { Cart } from '../database/models/cartEntity';
import { Order } from '../database/models/orderEntity';
import dbConnection from '../database';
import sendEmailfunc from './EmailSendor';
-import cron from "node-cron";
+import cron from 'node-cron';
import {
product_not_availble,
expiried_order} from './message.Templete';
-import { number } from 'joi';
-
export const eventEmitter = new EventEmitter();
-interface cart {
- id: number;
- user: UserModel;
- product: Product;
- quantity: number;
- createdAt: Date;
- updatedAt: Date;
-}
-
-interface userModel {
- id: number;
- firstName: string;
- lastName: string;
- email: string;
- picture: string | null;
-}
-
-interface product {
- id: number;
- name: string;
- image: string;
- gallery: string[];
- shortDesc: string;
- longDesc: string;
- quantity: number;
- regularPrice: number;
- salesPrice: number;
- tags: string[];
- type: string;
- isAvailable: boolean;
- averageRating: number;
- createdAt: Date;
- updatedAt: Date;
- vendor: UserModel;
-}
-
-interface order {
- id: number;
- user: UserModel | null;
- totalAmount: number;
- status: string;
- deliveryInfo: string | null;
- trackingNumber: string;
- createdAt: Date;
- updatedAt: Date;
- orderDetails: OrderDetails[];
- paid: boolean | null;
-}
-
-interface OrderDetails {
- id: number;
- order: Order;
- product: Product;
- quantity: number;
- price: number;
-}
-
const productRepository = dbConnection.getRepository(Product);
-const userRepository = dbConnection.getRepository(UserModel);
const NotificationRepository = dbConnection.getRepository(Notification_box);
-const cartRepository = dbConnection.getRepository(Cart);
const orderRepository = dbConnection.getRepository(Order);
diff --git a/src/controller/checkforproductchange.ts b/src/controller/checkforproductchange.ts
deleted file mode 100644
index 857ad40..0000000
--- a/src/controller/checkforproductchange.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-import Product from '../database/models/productEntity'
-import UserModel from '../database/models/userModel'
-
-
diff --git a/src/database/models/inbox_notification.ts b/src/database/models/inbox_notification.ts
index 4427afa..f31d906 100644
--- a/src/database/models/inbox_notification.ts
+++ b/src/database/models/inbox_notification.ts
@@ -1,4 +1,4 @@
-import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn,ManyToOne } from 'typeorm';
+import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn} from 'typeorm';
@Entity()
diff --git a/src/index.ts b/src/index.ts
index 37e37e9..ae24f29 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,7 +1,6 @@
/* eslint-disable no-console */
import app from './app';
import { DbConnection } from './database';
-import cron from 'node-cron'
import cron_tasks from '../src/Notification.vendor/node.cron.services'
declare module 'express' {
export interface Request {