ecomm/__tests__/services/sendGrid.test.ts

26 lines
1 KiB
TypeScript
Raw Normal View History

2023-06-13 13:10:17 +00:00
// import { config } from "dotenv";
// import { User, Order } from "../mongoose/Schema";
// import client from '@sendgrid/mail';
// config();
// export async function sendEmailasync(orderId:string, userId: string) {
// console.log(`Sending email for order ${orderId} to user ${userId}`);
// try {
// client.setApiKey(process.env.SENDGRID_API_KEY);
// const msg = {
// to: await User.findOne({ _id: userId }).select('email'),
// from: process.env.EMAIL_FROM,
// subject: 'Order Confirmation',
// text: 'Your order has been placed',
// html: '<strong>Thank you for shopping with us!</strong>'
// };
// await client.send(msg);
// console.log(`Email sent for order ${orderId} to user ${userId}`);
// // Update the order to indicate email has been sent
// await Order.findOne({ _id: orderId }).updateOne({ emailSent: true });
// console.log(`Updated order ${orderId} to indicate email has been sent`);
// return;
// } catch (error) {
// console.error('Error sending email:', error);
// }
// };