mirror of
https://github.com/sergeyyarkov/digital-store.git
synced 2026-10-11 18:29:11 +03:00
date format
This commit is contained in:
parent
5d8a8bcf46
commit
490de0989a
@ -80,22 +80,28 @@ function getItemsRoute(req, res, dbo) {
|
||||
}
|
||||
|
||||
function onePageItemRoute(req, res, dbo) {
|
||||
dbo.collection('items').find({_id: new ObjectID(req.params.id)}).toArray((err, result) => {
|
||||
const item = result[0];
|
||||
dbo.collection('categories').find({title: item.category}).toArray((err, result) => {
|
||||
const category = result[0];
|
||||
res.render('product', {
|
||||
title: item.title,
|
||||
image: category.img,
|
||||
count: item.count,
|
||||
category: item.category[0].toUpperCase() + item.category.slice(1),
|
||||
price: item.price,
|
||||
description: item.description,
|
||||
date: item.date,
|
||||
id: item._id
|
||||
})
|
||||
});
|
||||
})
|
||||
try {
|
||||
dbo.collection('items').find({_id: ObjectID(req.params.id)}).toArray((err, result) => {
|
||||
const item = result[0];
|
||||
dbo.collection('categories').find({title: item.category}).toArray((err, result) => {
|
||||
const category = result[0];
|
||||
res.render('product', {
|
||||
title: item.title,
|
||||
image: category.img,
|
||||
count: item.count,
|
||||
category: item.category[0].toUpperCase() + item.category.slice(1),
|
||||
price: item.price,
|
||||
description: item.description,
|
||||
date: item.date,
|
||||
id: item._id,
|
||||
type: category.type,
|
||||
format: category.format
|
||||
})
|
||||
});
|
||||
})
|
||||
} catch (error) {
|
||||
res.send('Error 404');
|
||||
}
|
||||
}
|
||||
|
||||
function howToBuyRoute(req, res) {
|
||||
|
||||
2
dist/public/js/bundle.js
vendored
2
dist/public/js/bundle.js
vendored
@ -4050,7 +4050,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) *
|
||||
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"renderItems\", function() { return renderItems; });\nfunction renderItems(categories, items) {\n var arrayCategories = categories;\n var arrayItems = items;\n var html = '';\n arrayCategories.forEach(function (category) {\n html += \"<div class=\\\"items-category\\\">\\n <h2 class=\\\"small-title\\\">\".concat(category.title, \"</h2>\\n </div>\");\n arrayItems.forEach(function (item) {\n if (item.category.toLowerCase() === category.title.toLowerCase()) {\n html += \"\\n <div data-id=\\\"\".concat(item._id, \"\\\" data-title=\\\"\").concat(item.title, \"\\\" data-price=\\\"\").concat(item.price, \"\\\" class=\\\"items-list\\\">\\n <div class=\\\"items-list__name\\\">\\n <div class=\\\"list-icon\\\">\\n <img src=\\\"./img/service-icons/\").concat(category.img, \"\\\" alt=\\\"#\\\">\\n </div>\\n <div class=\\\"list-title\\\">\\n <a href=\\\"/product/\").concat(item._id, \"\\\">\").concat(item.title, \"</a>\\n </div>\\n </div>\\n <div class=\\\"items-list__info\\\">\\n <div class=\\\"list-date\\\">\\n <small>\").concat(item.date.split('T')[0], \"</small>\\n </div>\\n <div class=\\\"list-count\\\">\\n <span>\").concat(item.count, \" \\u0448\\u0442.</span>\\n </div>\\n <div class=\\\"list-one\\\">\\n <span>\\u0426\\u0435\\u043D\\u0430 \\u0437\\u0430 1 \\u0448\\u0442.</span>\\n </div>\\n <div class=\\\"list-price\\\">\\n <span>\").concat(item.price.toFixed(2), \"\\u20BD</span>\\n </div>\\n <div class=\\\"list-buttons\\\">\\n <button data-id=\\\"\").concat(item._id, \"\\\" data-title=\\\"\").concat(item.title, \"\\\" data-date=\\\"\").concat(item.date, \"\\\" data-count=\\\"\").concat(item.count, \"\\\" data-price=\\\"\").concat(item.price, \"\\\" id=\\\"payOpen\\\" class=\\\"btn-small waves-effect waves-light\\\">\\u041A\\u0443\\u043F\\u0438\\u0442\\u044C</button>\\n <button data-id=\\\"\").concat(item._id, \"\\\" data-title=\\\"\").concat(item.title, \"\\\" data-date=\\\"\").concat(item.date, \"\\\" data-count=\\\"\").concat(item.count, \"\\\" data-price=\\\"\").concat(item.price, \"\\\" id=\\\"addItem\\\" class=\\\"btn-small waves-effect waves-light\\\"><i\\n class=\\\"material-icons\\\">shopping_cart</i></button>\\n </div>\\n </div>\\n </div>\");\n }\n });\n });\n return html;\n}\n\n//# sourceURL=webpack:///./src/js/templates/items.template.js?");
|
||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"renderItems\", function() { return renderItems; });\nfunction renderItems(categories, items) {\n var arrayCategories = categories;\n var arrayItems = items;\n var html = '';\n arrayCategories.forEach(function (category) {\n html += \"<div class=\\\"items-category\\\">\\n <h2 class=\\\"small-title\\\">\".concat(category.title, \"</h2>\\n </div>\");\n arrayItems.forEach(function (item) {\n if (item.category.toLowerCase() === category.title.toLowerCase()) {\n html += \"\\n <div data-id=\\\"\".concat(item._id, \"\\\" data-title=\\\"\").concat(item.title, \"\\\" data-price=\\\"\").concat(item.price, \"\\\" class=\\\"items-list\\\">\\n <div class=\\\"items-list__name\\\">\\n <div class=\\\"list-icon\\\">\\n <img src=\\\"./img/service-icons/\").concat(category.img, \"\\\" alt=\\\"#\\\">\\n </div>\\n <div class=\\\"list-title\\\">\\n <a href=\\\"/product/\").concat(item._id, \"\\\">\").concat(item.title, \"</a>\\n </div>\\n </div>\\n <div class=\\\"items-list__info\\\">\\n <div class=\\\"list-date\\\">\\n <small>\").concat(diffDates(new Date(), new Date(item.date)), \"</small>\\n </div>\\n <div class=\\\"list-count\\\">\\n <span>\").concat(item.count, \" \\u0448\\u0442.</span>\\n </div>\\n <div class=\\\"list-one\\\">\\n <span>\\u0426\\u0435\\u043D\\u0430 \\u0437\\u0430 1 \\u0448\\u0442.</span>\\n </div>\\n <div class=\\\"list-price\\\">\\n <span>\").concat(item.price.toFixed(2), \"\\u20BD</span>\\n </div>\\n <div class=\\\"list-buttons\\\">\\n <button data-id=\\\"\").concat(item._id, \"\\\" data-title=\\\"\").concat(item.title, \"\\\" data-date=\\\"\").concat(item.date, \"\\\" data-count=\\\"\").concat(item.count, \"\\\" data-price=\\\"\").concat(item.price, \"\\\" id=\\\"payOpen\\\" class=\\\"btn-small waves-effect waves-light\\\">\\u041A\\u0443\\u043F\\u0438\\u0442\\u044C</button>\\n <button data-id=\\\"\").concat(item._id, \"\\\" data-title=\\\"\").concat(item.title, \"\\\" data-date=\\\"\").concat(item.date, \"\\\" data-count=\\\"\").concat(item.count, \"\\\" data-price=\\\"\").concat(item.price, \"\\\" id=\\\"addItem\\\" class=\\\"btn-small waves-effect waves-light\\\"><i\\n class=\\\"material-icons\\\">shopping_cart</i></button>\\n </div>\\n </div>\\n </div>\");\n }\n });\n });\n return html;\n}\n\nfunction diffDates(firstDate, secondDate) {\n var diff = Math.floor((firstDate - secondDate) / (60 * 60 * 24 * 1000));\n\n if (diff <= 0) {\n return 'добавлено сегодня';\n }\n\n return diff + ' дней назад';\n}\n\n//# sourceURL=webpack:///./src/js/templates/items.template.js?");
|
||||
|
||||
/***/ }),
|
||||
|
||||
|
||||
10
dist/views/product.pug
vendored
10
dist/views/product.pug
vendored
@ -23,7 +23,7 @@ main.main-section
|
||||
.product-title.block-title
|
||||
h1 #{title}
|
||||
br
|
||||
small(style="font-size: 12px") Дата добавления: #{date}
|
||||
small(style="font-size: 12px") Дата добавления: #{date.toLocaleDateString()}
|
||||
.product-info
|
||||
.product-info__left
|
||||
#pay-js.product-left__pay
|
||||
@ -42,13 +42,9 @@ main.main-section
|
||||
p #{description}
|
||||
.product-right__content
|
||||
h2 Тип аккаунтов #{category}
|
||||
p
|
||||
| Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos tempora quidem
|
||||
| velit facilis exercitationem eveniet porro vitae quisquam officia.
|
||||
| Explicabo, iure quis doloribus totam nihil esse minus, vero animi ex
|
||||
| corrupti ea officia, dolor fuga itaque ad deserunt quo. Sint!
|
||||
p #{type}
|
||||
h2 Формат аккаунтов #{category}
|
||||
p Lorem ipsum dolor sit amet consectetur adipisicing elit. Animi, magni.
|
||||
p #{format}
|
||||
hr
|
||||
h3 Рекомендации к покупке аккаунтов.
|
||||
p
|
||||
|
||||
@ -22,7 +22,7 @@ export function renderItems(categories, items) {
|
||||
</div>
|
||||
<div class="items-list__info">
|
||||
<div class="list-date">
|
||||
<small>${item.date.split('T')[0]}</small>
|
||||
<small>${diffDates(new Date(), new Date(item.date))}</small>
|
||||
</div>
|
||||
<div class="list-count">
|
||||
<span>${item.count} шт.</span>
|
||||
@ -42,8 +42,14 @@ export function renderItems(categories, items) {
|
||||
</div>`;
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
function diffDates(firstDate, secondDate) {
|
||||
let diff = Math.floor((firstDate - secondDate) / (60 * 60 * 24 * 1000));
|
||||
if (diff <= 0) {
|
||||
return 'добавлено сегодня';
|
||||
}
|
||||
return diff + ' дней назад';
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user