added markdown

This commit is contained in:
Sergey Yarkov 2020-05-17 02:16:39 +03:00
parent 78b2cc8425
commit 1089b313ab
7 changed files with 2565 additions and 2594 deletions

View File

@ -19,7 +19,7 @@ main.main-section
p p
strong Контакты strong Контакты
p   p  
p(style="white-space: pre-wrap;") #{store.contacts} != store.contacts
//- Footer Template //- Footer Template

View File

@ -19,7 +19,7 @@ main.main-section
p p
strong Для того, чтобы купить аккаунты в магазине, нужно проделать следующие шаги: strong Для того, чтобы купить аккаунты в магазине, нужно проделать следующие шаги:
p   p  
p(style="white-space: pre-wrap;") #{store.howToBuy} != store.howToBuy
//- Footer Template //- Footer Template

View File

@ -16,7 +16,7 @@ main.main-section
.information-title .information-title
h2.small-title Важная информация: h2.small-title Важная информация:
.information-text .information-text
p(style="white-space: pre-wrap;") #{store.info} != store.info
.information-close .information-close
button#information-close.waves-effect.btn.red Закрыть button#information-close.waves-effect.btn.red Закрыть
// Information Block END // Information Block END
@ -95,7 +95,7 @@ main.main-section
.items-info__title.block-title .items-info__title.block-title
i.material-icons info i.material-icons info
h3.med-title Информация h3.med-title Информация
p(style="white-space: pre-wrap;") #{store.infoBottom} != store.infoBottom
// Items Block END // Items Block END
//- Footer Template //- Footer Template

View File

@ -39,15 +39,15 @@ main.main-section
.product-right__title .product-right__title
span Описание: span Описание:
hr hr
p #{description} != description
.product-right__content .product-right__content
h2 Тип аккаунтов #{category} h2 Тип аккаунтов #{category}
p #{type} != type
h2 Формат аккаунтов #{category} h2 Формат аккаунтов #{category}
p #{format} != format
hr hr
h3 Рекомендации к покупке аккаунтов. h3 Рекомендации к покупке аккаунтов.
p #{store.recommendations} != store.recommendations
h3 Отзывы о товаре h3 Отзывы о товаре
#disqus_thread #disqus_thread

4802
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -27,6 +27,7 @@
"express-flash": "0.0.2", "express-flash": "0.0.2",
"express-session": "^1.17.0", "express-session": "^1.17.0",
"log4js": "^6.1.0", "log4js": "^6.1.0",
"marked": "^1.1.0",
"method-override": "^3.0.0", "method-override": "^3.0.0",
"mongodb": "^3.3.4", "mongodb": "^3.3.4",
"multer": "^1.4.2", "multer": "^1.4.2",

View File

@ -1,162 +1,178 @@
const ObjectID = require('mongodb').ObjectID; const ObjectID = require('mongodb').ObjectID
const nodemailer = require('../config/nodemailer.config'); const marked = require('marked')
const nodemailer = require('../config/nodemailer.config')
module.exports = function (server, db) { module.exports = function (server, db) {
server.get('/', async (req, res) => { server.get('/', async (req, res) => {
try { try {
const store = await db.collection('content').findOne({}); const store = await db.collection('content').findOne({})
db.collection('categories').find().toArray((err, result) => { db.collection('categories')
const categories = result.map(category => category.title[0].toUpperCase() + category.title.slice(1)); .find()
.toArray((err, result) => {
const categories = result.map(
(category) =>
category.title[0].toUpperCase() + category.title.slice(1)
)
res.render('main/index', { res.render('main/index', {
pageName: 'index', pageName: 'index',
title: `${store.title} | Главная`, title: `${store.title} | Главная`,
categories, categories,
store: { store: {
title: store.title, title: store.title,
info: store.info, info: marked(store.info),
infoBottom: store.infoBottom, infoBottom: marked(store.infoBottom),
color: store.color color: store.color,
} },
}); })
}); })
} catch { } catch {
res.status(500).render('main/404'); res.status(500).render('main/404')
} }
}); })
server.get('/how-to-buy', async (req, res) => { server.get('/how-to-buy', async (req, res) => {
try { try {
const store = await db.collection('content').findOne({}); const store = await db.collection('content').findOne({})
res.render('main/how-to-buy', { res.render('main/how-to-buy', {
pageName: 'how-to-buy', pageName: 'how-to-buy',
title: `${store.title} | Как купить товар`, title: `${store.title} | Как купить товар`,
store: { store: {
title: store.title, title: store.title,
howToBuy: store.howToBuy, howToBuy: marked(store.howToBuy),
color: store.color color: store.color,
} },
}); })
} catch { } catch {
res.status(500).render('main/404'); res.status(500).render('main/404')
} }
}); })
server.get('/contacts', async (req, res) => { server.get('/contacts', async (req, res) => {
try { try {
const store = await db.collection('content').findOne({}); const store = await db.collection('content').findOne({})
res.render('main/contacts', { res.render('main/contacts', {
pageName: 'contacts', pageName: 'contacts',
title: `${store.title} | Контакты`, title: `${store.title} | Контакты`,
store: { store: {
title: store.title, title: store.title,
contacts: store.contacts, contacts: marked(store.contacts),
color: store.color color: store.color,
} },
}); })
} catch { } catch {
res.status(500).render('main/404'); res.status(500).render('main/404')
} }
}); })
server.get('/comments', async (req, res) => { server.get('/comments', async (req, res) => {
try { try {
const store = await db.collection('content').findOne({}); const store = await db.collection('content').findOne({})
res.render('main/comments', { res.render('main/comments', {
pageName: 'comments', pageName: 'comments',
title: `${store.title} | Отзывы`, title: `${store.title} | Отзывы`,
store: { store: {
title: store.title, title: store.title,
color: store.color color: store.color,
} },
}); })
} catch { } catch {
res.status(500).render('main/404'); res.status(500).render('main/404')
} }
}); })
server.get('/my-orders', async (req, res) => { server.get('/my-orders', async (req, res) => {
try { try {
const store = await db.collection('content').findOne({}); const store = await db.collection('content').findOne({})
res.render('main/my-orders', { res.render('main/my-orders', {
pageName: 'my-orders', pageName: 'my-orders',
title: `${store.title} | Мои покупки`, title: `${store.title} | Мои покупки`,
store: { store: {
title: store.title, title: store.title,
color: store.color color: store.color,
} },
});
} catch {
res.status(500).render('main/404');
}
});
server.get('/product/:id', async (req, res) => {
const store = await db.collection('content').findOne({});
const product = new Promise((resolve, reject) => {
db.collection('items').find({_id: ObjectID(req.params.id)}).toArray()
.then((items) => {
const item = items.find(item => item);
resolve(item);
});
});
product.then((item) => {
return new Promise((resolve, reject) => {
db.collection('categories').find({title: item.category}).toArray()
.then((categories) => {
const category = categories.find(category => category);
resolve({item, category});
});
});
}) })
.then(((data) => { } catch {
res.status(500).render('main/404')
}
})
server.get('/product/:id', async (req, res) => {
const store = await db.collection('content').findOne({})
const product = new Promise((resolve, reject) => {
db.collection('items')
.find({ _id: ObjectID(req.params.id) })
.toArray()
.then((items) => {
const item = items.find((item) => item)
resolve(item)
})
})
product
.then((item) => {
return new Promise((resolve, reject) => {
db.collection('categories')
.find({ title: item.category })
.toArray()
.then((categories) => {
const category = categories.find((category) => category)
resolve({ item, category })
})
})
})
.then((data) => {
const item = data.item, const item = data.item,
category = data.category; category = data.category
res.render('main/product', { res.render('main/product', {
title: item.title, title: item.title,
image: category.img, image: category.img,
count: item.count, count: item.count,
category: item.category[0].toUpperCase() + item.category.slice(1), category: item.category[0].toUpperCase() + item.category.slice(1),
price: item.price, price: item.price,
description: item.description, description: marked(item.description),
date: item.date, date: item.date,
id: item._id, id: item._id,
type: category.type, type: marked(category.type),
format: category.format, format: marked(category.format),
store: { store: {
title: store.title, title: store.title,
recommendations: store.recommendations, recommendations: marked(store.recommendations),
color: store.color color: store.color,
} },
}); })
})) })
.catch(() => { .catch(() => {
res.status(500).render('main/404'); res.status(500).render('main/404')
}); })
}); })
server.post('/my-orders', async (req, res) => { server.post('/my-orders', async (req, res) => {
const buyers = await db.collection('buyers').find({email: req.body.email}).toArray(); const buyers = await db
.collection('buyers')
.find({ email: req.body.email })
.toArray()
if (buyers.length > 0) { if (buyers.length > 0) {
// рендерим html // рендерим html
const html = buyers.map((buyer) => { const html = buyers.map((buyer) => {
return ` return `
<b>Номер заказа: ${buyer.bill_id}</b><br> <b>Номер заказа: ${buyer.bill_id}</b><br>
<b>Дата оплаты: ${new Date(buyer.date).toLocaleDateString()}</b><br> <b>Дата оплаты: ${new Date(
buyer.date
).toLocaleDateString()}</b><br>
<b>Данные товара:</b><br> <b>Данные товара:</b><br>
<p>${buyer.data.join('<br>')}</p> <p>${buyer.data.join('<br>')}</p>
<p>======================================================================</p> <p>======================================================================</p>
`; `
}); })
// высылаем данные покупателю // высылаем данные покупателю
try { try {
await nodemailer.transporter.sendMail({ await nodemailer.transporter.sendMail({
from: `"Ваши покупки." <${process.env.EMAIL_LOGIN}>`, from: `"Ваши покупки." <${process.env.EMAIL_LOGIN}>`,
to: req.body.email, to: req.body.email,
subject: "Данные купленных товаров находятся в этом письме.", subject: 'Данные купленных товаров находятся в этом письме.',
html: html.join('') html: html.join(''),
}); })
res.json({status: 'OK'}); res.json({ status: 'OK' })
} catch (error) { } catch (error) {
res.json({status: 'ERR'}); res.json({ status: 'ERR' })
} }
} else { } else {
res.json({status: 'NF'}); res.json({ status: 'NF' })
} }
}); })
} }