Skip to content

Commit

Permalink
ft (backend): fix all error of linting
Browse files Browse the repository at this point in the history
Feat: Product Lifecycle Notification System #84
  • Loading branch information
niyibi250 committed Jun 12, 2024
1 parent 01e6c36 commit 722cb1f
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 114 deletions.
28 changes: 28 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 19 additions & 20 deletions src/Notification.vendor/EmailSendor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]",
subject: 'Notification from Your Company',
text: messageContent,
html: `<p>${messageContent.replace(/\n/g, '<br>')}</p>`,
};
const mailOptions = {
from: `"The E-commerce Team" <${process.env.EMAIL_USER}>`,
to: vendorEmail,
subject: message_title,
text: messageContent,
html: `<p>${messageContent.replace(/\n/g, '<br>')}</p>`,
};

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);
}
Expand Down
21 changes: 0 additions & 21 deletions src/Notification.vendor/event.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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 } },
Expand Down
2 changes: 0 additions & 2 deletions src/Notification.vendor/message.Templete.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { string } from "joi";

interface UserModel {
id: number;
firstName: string;
Expand Down
65 changes: 1 addition & 64 deletions src/Notification.vendor/node.cron.services.ts
Original file line number Diff line number Diff line change
@@ -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);


Expand Down
4 changes: 0 additions & 4 deletions src/controller/checkforproductchange.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/database/models/inbox_notification.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn,ManyToOne } from 'typeorm';
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn} from 'typeorm';


@Entity()
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 722cb1f

Please sign in to comment.