如何解决SendGrid Node.js集成语法问题
我正在尝试使用SendGrid在创建新订单时发送电子邮件通知。到目前为止,它在创建订单时发送电子邮件,但是无法接收$ {order.products.map ...}中的任何数据。我正在使用vs代码,并且括号突出显示从该区域开始,看来我缺少一个右括号,但我看不到它。我是否只是错误地创建了此函数,而vs代码通过显示错误的突出显示来告诉我?
在看了很长时间之后,我不确定它到底出了什么问题,我只需要另一只眼睛来帮助我。
const create = async (req,res) => {
try {
console.log('CREATE ORDER: ',req.body)
req.body.order.user = req.profile
const order = new Order(req.body.order)
order.save((error,data) => {
const emailData = {
to: ['Payments@.com','@.com'],// admin
from: 'Payments@.com',subject: `A new order is received`,html: `
<h1>hey employee,get this stuff taken care of.</h1>
<h2>Customer name: ${order.user.first_name} ${order.user.last_name}</h2>
<h2>Customer address: ${order.delivery_address}</h2>
<h2>User's email: ${order.user.email}</h2>
<h2>Total products: ${order.products.length}</h2>
<h2>Products: ${order.products}</h2>
<h2>Order status: ${order.status}</h2>
<h2>Product details:</h2>
<hr />
${order.products
.map(p => {
return `<div>
<h3>Product Name: ${p.name}</h3>
<h3>Product Price: ${p.price}</h3>
<h3>Product Quantity: ${p.quantity}</h3>
<h3>Product Seller: ${p.shop}</h3>
</div>`;
})
.join('--------------------')}
<h2>Total order cost: ${order.amount}<h2>
<p>Login to your dashboard</a> to see the order in detail.</p>
`
}
sgMail
.send(emailData)
.then(sent => console.log('SENT >>>',sent))
.catch(err => console.log('ERR >>>',err));
// email to buyer
const emailData2 = {
to: [order.user.email,'Payments@.com'],from: 'Payments@.com',subject: `You order is in process`,html: `
<h1>hey ${order.user.first_name},Thank you for shopping with us.</h1>
<h2>Total products: ${order.products.length}</h2>
<h2>Order status: ${order.status}</h2>
<h2>Product details:</h2>
<hr />
${order.products
.map(p => {
return `<div>
<h3>Product Name: ${p.name}</h3>
<h3>Product Price: ${p.price}</h3>
<h3>Product Quantity: ${p.quantity}</h3>
</div>`;
})
.join('--------------------')}
<h2>Total order cost: ${order.amount}<h2>
<p>Thank your for shopping with us.</p>
`
}
sgMail
.send(emailData2)
.then(sent => console.log('SENT 2 >>>',sent))
.catch(err => console.log('ERR 2 >>>',err));
res.status(200).json(data)
})
} catch (err){
return res.status(400).json({
error: errorHandler.getErrorMessage(err)
})
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。