Skip to content

Commit

Permalink
resolve rebase conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
niyibi250 committed Jun 14, 2024
1 parent 53d0a50 commit 3966b3b
Show file tree
Hide file tree
Showing 9 changed files with 10,032 additions and 44 deletions.
9,972 changes: 9,972 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@
"coveragePathIgnorePatterns": [
"/node_modules/",
"/src/emails/",
"/src/utilis/"
"/src/utilis/",
"/src/Notification.vendor/"
],
"testPathIgnorePatterns": [
"/node_modules/",
"/src/emails/",
"/src/middlewares/",
"/src/utilis/"
"/src/utilis/",
"/src/Notification.vendor/"
]
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/Notification.vendor/EmailSendor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ async function sendEmail(vendorEmail: string, message_title: string, messageCont

const mailOptions = {
from: `"The E-commerce Team" <${process.env.EMAIL_USER}>`,
to: '[email protected]',
to: vendorEmail,
subject: 'Notification from Your Company',
text: messageContent,
html: `<p>${messageContent.replace(/\n/g, '<br>')}</p>`,
};

await transporter.sendMail(mailOptions);
console.log('Email sent successfully');

} catch (error) {
throw error
}
Expand Down
61 changes: 40 additions & 21 deletions src/Notification.vendor/event.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const orderRepository = dbConnection.getRepository(Order);

eventEmitter.on('addToCart', async (product_id, userId) => {
try {

if (process.env.NODE_ENV == 'test'){
return
}
const product = await productRepository.findOne({
where: { id: product_id },
select: { vendor: { firstName: true, lastName: true, picture: true, id: true, email: true } },
Expand Down Expand Up @@ -96,15 +98,20 @@ eventEmitter.on('addToCart', async (product_id, userId) => {
new_notification.message_title = 'your product is add to buyer cart';
new_notification.message_content = added_to_cart_message(product, User);
await NotificationRepository.save(new_notification);
sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
} catch (error) {
throw error
await sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)

}
catch (error) {
throw error

}
});

eventEmitter.on('removeItem', async (removeItem) => {
try {

if (process.env.NODE_ENV == 'test'){
return
}
const product = await productRepository.findOne({
where: { id: removeItem.product.id },
select: { vendor: { firstName: true, lastName: true, picture: true, id: true, email: true } },
Expand Down Expand Up @@ -135,7 +142,7 @@ eventEmitter.on('removeItem', async (removeItem) => {
new_notification.message_content = removed_to_cart_message(product, user);

await NotificationRepository.save(new_notification);
sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
await sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)

} catch (error) {
throw error
Expand All @@ -144,6 +151,9 @@ eventEmitter.on('removeItem', async (removeItem) => {

eventEmitter.on('pressorder', async (order:order) => {
try {
if (process.env.NODE_ENV == 'test'){
return
}
const orderDetail = order.orderDetails
for(let i=0; i<orderDetail.length; i++)
{
Expand All @@ -170,7 +180,7 @@ eventEmitter.on('pressorder', async (order:order) => {

await NotificationRepository.save(new_notification);

sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
await sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
}

}
Expand All @@ -181,7 +191,9 @@ eventEmitter.on('pressorder', async (order:order) => {

eventEmitter.on('order_status_change', async (orderId:number) => {
try {

if (process.env.NODE_ENV == 'test'){
return
}
const order = await orderRepository.findOne({
where: {
id: orderId,
Expand All @@ -190,7 +202,6 @@ eventEmitter.on('order_status_change', async (orderId:number) => {
});
if(order == null)
{
console.log('order is null')
return
}
const orderDetail = order.orderDetails
Expand Down Expand Up @@ -219,9 +230,9 @@ eventEmitter.on('order_status_change', async (orderId:number) => {
new_notification.message_content = order_status_changed(product, order);

await NotificationRepository.save(new_notification);
sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
await sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
}

}
catch (error) {
throw error
Expand All @@ -231,7 +242,9 @@ eventEmitter.on('order_status_change', async (orderId:number) => {

eventEmitter.on('productCreated', async(product:product)=>{
try{

if (process.env.NODE_ENV == 'test'){
return
}
if(!product)
{
return
Expand All @@ -249,7 +262,7 @@ eventEmitter.on('productCreated', async(product:product)=>{
new_notification.message_content = new_product_created(product);

await NotificationRepository.save(new_notification);
sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
await sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
}
catch(error)
{
Expand All @@ -261,7 +274,9 @@ eventEmitter.on('productCreated', async(product:product)=>{
eventEmitter.on('product_updated', async(product:product)=>{

try{

if (process.env.NODE_ENV == 'test'){
return
}
if(!product)
{
return
Expand All @@ -278,7 +293,7 @@ eventEmitter.on('product_updated', async(product:product)=>{
new_notification.message_content = updated_Product(product);

await NotificationRepository.save(new_notification);
sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
await sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
}
catch(error)
{
Expand All @@ -289,7 +304,9 @@ eventEmitter.on('product_updated', async(product:product)=>{

eventEmitter.on('product_deleted', async(product_id:number)=>{
try{

if (process.env.NODE_ENV == 'test'){
return
}
const product= await productRepository.findOne({
where:{id: product_id},
relations:['vendor']
Expand All @@ -307,11 +324,11 @@ eventEmitter.on('product_deleted', async(product_id:number)=>{
new_notification.product_id =product.id ;
new_notification.vendor_id = product.vendor.id
new_notification.vendor_email = product.vendor.email;
new_notification.message_title = 'Your product was Updated succesfull';
new_notification.message_title = 'Your product was deleted succesfull';
new_notification.message_content = product_deleted(product);

await NotificationRepository.save(new_notification);
sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
await sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
}
catch(error)
{
Expand All @@ -322,7 +339,9 @@ eventEmitter.on('product_deleted', async(product_id:number)=>{

eventEmitter.on('order_canceled', async (orderId) => {
try {

if (process.env.NODE_ENV == 'test'){
return
}
const order = await orderRepository.findOne({
where: { id: orderId },
relations: ['orderDetails','orderDetails.product', 'orderDetails.product.vendor'],
Expand Down Expand Up @@ -354,12 +373,12 @@ eventEmitter.on('order_canceled', async (orderId) => {
new_notification.product_id = orderDetail[i].product.id;
new_notification.vendor_id = product.vendor.id
new_notification.vendor_email = product.vendor.email;
new_notification.message_title = 'order with you product was placed';
new_notification.message_title = 'order with you product was cancaled';
new_notification.message_content = order_canceled(product, order);

await NotificationRepository.save(new_notification);

sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
await sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
}

}
Expand Down
3 changes: 0 additions & 3 deletions src/Notification.vendor/node.cron.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ const dailyTasks = cron.schedule('0 0 * * *', async () => {

await NotificationRepository.save(new_notification);

console.log('press order notification created')
sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
}

console.log(`Order ${order.id} cancelled due to expiry.`);
}
}

Expand All @@ -88,7 +86,6 @@ const dailyTasks = cron.schedule('0 0 * * *', async () => {

await NotificationRepository.save(new_notification);

console.log('press order notification created')
sendEmailfunc(product.vendor.email, new_notification.message_title, new_notification.message_content)
}
});
Expand Down
24 changes: 12 additions & 12 deletions src/__test__/notification.vendor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import { getVendorToken, afterAllHook, beforeAllHook } from './testSetup';
import Notification_box from '../database/models/inbox_notification';
import dbConnection from '../database';

const notificationRepository = dbConnection.getRepository(Notification_box);

beforeAll(beforeAllHook);
afterAll(afterAllHook);

describe('Notification Controller Tests', () => {
let token: string;
let vendor_id: number;
let notificationRepository;
let notificationId: number;
let notification_id: number

beforeAll(async () => {
token = await getVendorToken();
notificationRepository = dbConnection.getRepository(Notification_box);

// make notification for test
// ------------------------------------------
Expand All @@ -27,10 +27,8 @@ describe('Notification Controller Tests', () => {
notification.vendor_id = 1;
const savedNotification = await notificationRepository.save(notification);
// --------------------------------------------------
notificationId = savedNotification.notification_id;
vendor_id = savedNotification.vendor_id

console.log(`Created notification with ID: ${notificationId}`);
notification_id = savedNotification.notification_id
});

it('should retrieve all notifications', async () => {
Expand All @@ -53,18 +51,20 @@ describe('Notification Controller Tests', () => {
expect(Array.isArray(response.body.notification)).toBeTruthy();
});

it('should delete all notifications', async () => {
it('should delete notification by notification ID', async () => {
const response = await request(app)
.delete('/api/v1/notification/vendor')
.delete(`/api/v1/notification/vendor/${notification_id}`)
.set('Authorization', `Bearer ${token}`);

expect(response.statusCode).toEqual(200);
expect(response.body.msg).toEqual('All notifications deleted successfully');
});

it('should delete a notification by ID', async () => {
const response = await request(app).delete(`/api/v1/notification/vendor/53`)

it('should delete all notifications', async () => {
const response = await request(app)
.delete('/api/v1/notification/vendor')

expect(response.statusCode).toEqual(200);
expect(response.body.msg).toEqual('All notifications deleted successfully');
});


Expand Down
2 changes: 1 addition & 1 deletion src/controller/cartController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const addToCart = errorHandler(async (req: Request, res: Response) => {
newItem.quantity = quantity;

const savedItem = await cartRepository.save(newItem);
console.log('caller the event')

eventEmitter.emit('addToCart',productId, userId)

return res
Expand Down
2 changes: 0 additions & 2 deletions src/controller/notificationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const getallNotification= errorHandler(

export const deleteallNotification = errorHandler(
async (req: Request , res: Response)=>{
const vendorId = req.params.id
const Notication = await NotificationRepository.find()
if(!Notication)
{
Expand All @@ -46,7 +45,6 @@ export const deletenotification = errorHandler(
where: { notification_id: id }
});

console.log(`this is the notification:${notification}`)

if (!notification) {
return res.status(400).json({ msg: 'No Notifications was found' });
Expand Down
2 changes: 1 addition & 1 deletion src/routes/notificationRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ notificationRouter.route('/vendor')
.get(getallNotification)
.delete(deleteallNotification)
notificationRouter.route('/vendor/:id')
.delete(deletenotification)
.delete(IsLoggedIn,checkRole(['Vendor']),deletenotification)
.get(IsLoggedIn,checkRole(['Vendor']),getvendorNotifications)

export default notificationRouter

0 comments on commit 3966b3b

Please sign in to comment.