I am encountering an issue where I have a sample document stored in a mongo atlas database:
{
"_id": {
"$oid": "5e517a946364cc48f0ccf1e7"
},
"firstName": "checkout1",
"lastName": "",
"companyName": "",
"phoneNumber": null,
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="04617c65697468616169656d68446369656d682a676b69">[email protected]</a>",
"country": "",
"adress": "",
"postcode": "",
"userId": "5daf414818d091616a0d917e",
"orderedItems": [{
"_id": "5e03b2072e0c98b9fa62388c",
"id": 3,
"title": "Blue shoes",
"img1": "product4/1.jpg",
"img2": "product4/2.jpg",
"cost": 70,
"color": "blue",
"quantity": 5
}],
"createdAt": {
"$date": "2020-02-22T19:01:40.228Z"
},
"updatedAt": {
"$date": "2020-02-22T19:01:40.228Z"
},
"__v": 0
}
I am looking to send a confirmation message regarding purchased items and their quantity as demonstrated below:
...
const {
...
email,
orderedItems
} = req.body;
var user = await User.findOne({ email: email });
let newCheckout = await Checkout.create({
...
email,
...
orderedItems,
userId: user._id
});
const htmlEmail = `
<div>Title of first ordered item: ${newCheckout.orderedItems[0].title}</div>
`;
const mailOptions = {
from: process.env.MY_TEST_EMAIL_ADRESS,
to: process.env.MY_EMAIL_ADRESS,
subject: 'new message',
replyTo: process.env.MY_EMAIL_ADRESS,
text: process.env.MY_TEST_EMAIL_ADRESS,
html: htmlEmail
};
transporter.sendMail(mailOptions, (err, info) => {});
...
I require this segment of code:
const htmlEmail = `
<div>Title of first ordered item: ${newCheckout.orderedItems[0].title}</div>
`;
To structure it similar to React where I can map the orderedItems array to div elements so that the final message would appear something like this (the user would receive all ordered item titles, and the number of div elements would vary based on the array length):
<div>Item: ${newCheckout.orderedItems[0].title}</div>
<div>Item: ${newCheckout.orderedItems[1].title}</div>
<div>Item: ${newCheckout.orderedItems[2].title}</div>
My main query is whether this task can be accomplished without using template engines such as Jade, Pug, Mustache?