diff --git a/config/routes/main.js b/config/routes/main.js
index a418720..26d1850 100644
--- a/config/routes/main.js
+++ b/config/routes/main.js
@@ -1,4 +1,5 @@
const ObjectID = require('mongodb').ObjectID;
+const nodemailer = require('../nodemailer.config');
module.exports = function (server, db) {
server.get('/', async (req, res) => {
@@ -121,4 +122,34 @@ module.exports = function (server, db) {
res.status(500).render('main/404');
});
});
+ server.post('/my-orders', async (req, res) => {
+ const buyers = await db.collection('buyers').find({email: req.body.email}).toArray();
+ if (buyers.length > 0) {
+ // рендерим html
+ const html = buyers.map((buyer) => {
+ return `
+ Номер заказа: ${buyer.bill_id}
+ Дата оплаты: ${new Date(buyer.date).toLocaleDateString()}
+ Данные товара:
+
${buyer.data.join('
')}
======================================================================
+ `; + }); + + // высылаем данные покупателю + try { + await nodemailer.transporter.sendMail({ + from: `"Ваши покупки." <${process.env.EMAIL_LOGIN}>`, + to: req.body.email, + subject: "Данные купленных товаров находятся в этом письме.", + html: html.join('') + }); + res.json({status: 'OK'}); + } catch (error) { + res.json({status: 'ERR'}); + } + } else { + res.json({status: 'NF'}); + } + }); } diff --git a/config/routes/success.js b/config/routes/success.js index c485cc5..03f8898 100644 --- a/config/routes/success.js +++ b/config/routes/success.js @@ -34,14 +34,14 @@ module.exports = function(server, db, qiwiApi) { db.collection('buyers').insertOne({bill_id, email, method, date, amount, data: result}); await nodemailer.transporter.sendMail({ - from: `"Оплата аккаунта." <${process.env.EMAIL_LOGIN}>`, // sender address - to: email, // list of receivers - subject: "Оплата успешно проведена.", // subject - text: "Данные купленного товара находятся в этом письме.", // plain text body + from: `"Оплата аккаунта." <${process.env.EMAIL_LOGIN}>`, + to: email, + subject: "Оплата успешно проведена.", + text: "Данные купленного товара находятся в этом письме.", html: `Номер заказа: ${bill_id}${result.join('
')}
Вы не добавили ни один товар
'}},{key:"removeItem",value:function(t){if("removeItem"===t.target.id){var e,n=t.target.dataset.id;this.items.cart.forEach((function(t,i){return t.id===n&&(e=i)})),this.items.cart.splice(e,1),localStorage.setItem("cart",JSON.stringify(this.items.cart)),this.list.innerHTML="",this.insertItems(this.list),this.defaultBtnColor(n)}}},{key:"insertTotalPrice",value:function(t,e){var n=0;e.forEach((function(t){return n+=parseFloat(t.price)})),this.$el.querySelector("#".concat(t)).innerHTML="".concat(n.toFixed(2),"₽")}},{key:"makePay",value:function(t){var e,n,i;return regeneratorRuntime.async((function(o){for(;;)switch(o.prev=o.next){case 0:return t.preventDefault(),e={items:this.items.cart.map((function(t){return{id:t.id,title:t.title,price:parseFloat(t.price)}}))},n=0,e.items.forEach((function(t){return n+=parseFloat(t.price)})),e.totalPrice=Math.round(100*n)/100,e.payMethod=this.$el.querySelector(".payment-field input").value,e.email=this.$el.querySelector(".email-field input").value,o.next=9,regeneratorRuntime.awrap(C.a.put("/payment",e));case 9:(i=o.sent).data.payUrl?document.location.href=i.data.payUrl:alert(i.data);case 11:case"end":return o.stop()}}),null,this)}},{key:"defaultBtnColor",value:function(t){this.items.roster&&this.items.roster.querySelector('#rosterButtons[data-id="'.concat(t,'"] #addItem'))&&(this.items.roster.querySelector('#rosterButtons[data-id="'.concat(t,'"] #addItem')).classList.remove("orange"),this.items.roster.querySelector('#rosterButtons[data-id="'.concat(t,'"] #addItem i')).innerHTML="shopping_cart")}}])&&pt(n.prototype,i),o&&pt(n,o),e}(ct);function _t(t){return(_t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function bt(t,e){for(var n=0;nВы не добавили ни один товар
'}},{key:"removeItem",value:function(t){if("removeItem"===t.target.id){var e,n=t.target.dataset.id;this.items.cart.forEach((function(t,i){return t.id===n&&(e=i)})),this.items.cart.splice(e,1),localStorage.setItem("cart",JSON.stringify(this.items.cart)),this.list.innerHTML="",this.insertItems(this.list),this.defaultBtnColor(n)}}},{key:"insertTotalPrice",value:function(t,e){var n=0;e.forEach((function(t){return n+=parseFloat(t.price)})),this.$el.querySelector("#".concat(t)).innerHTML="".concat(n.toFixed(2),"₽")}},{key:"makePay",value:function(t){var e,n,i;return regeneratorRuntime.async((function(o){for(;;)switch(o.prev=o.next){case 0:return t.preventDefault(),e={items:this.items.cart.map((function(t){return{id:t.id,title:t.title,price:parseFloat(t.price)}}))},n=0,e.items.forEach((function(t){return n+=parseFloat(t.price)})),e.totalPrice=Math.round(100*n)/100,e.payMethod=this.$el.querySelector(".payment-field input").value,e.email=this.$el.querySelector(".email-field input").value,o.next=9,regeneratorRuntime.awrap(C.a.put("/payment",e));case 9:(i=o.sent).data.payUrl?document.location.href=i.data.payUrl:alert(i.data);case 11:case"end":return o.stop()}}),null,this)}},{key:"defaultBtnColor",value:function(t){this.items.roster&&this.items.roster.querySelector('#rosterButtons[data-id="'.concat(t,'"] #addItem'))&&(this.items.roster.querySelector('#rosterButtons[data-id="'.concat(t,'"] #addItem')).classList.remove("orange"),this.items.roster.querySelector('#rosterButtons[data-id="'.concat(t,'"] #addItem i')).innerHTML="shopping_cart")}}])&&pt(n.prototype,i),o&&pt(n,o),e}(ct);function _t(t){return(_t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function bt(t,e){for(var n=0;n