diff --git a/config/routes/routes.js b/config/routes/routes.js index ac559a9..783c995 100644 --- a/config/routes/routes.js +++ b/config/routes/routes.js @@ -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) { diff --git a/dist/public/js/bundle.js b/dist/public/js/bundle.js index 16553ef..0a2dd12 100644 --- a/dist/public/js/bundle.js +++ b/dist/public/js/bundle.js @@ -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 += \"
\\n

\".concat(category.title, \"

\\n
\");\n arrayItems.forEach(function (item) {\n if (item.category.toLowerCase() === category.title.toLowerCase()) {\n html += \"\\n
\\n
\\n
\\n \\\"#\\\"\\n
\\n \\n
\\n
\\n
\\n \").concat(item.date.split('T')[0], \"\\n
\\n
\\n \").concat(item.count, \" \\u0448\\u0442.\\n
\\n
\\n \\u0426\\u0435\\u043D\\u0430 \\u0437\\u0430 1 \\u0448\\u0442.\\n
\\n
\\n \").concat(item.price.toFixed(2), \"\\u20BD\\n
\\n
\\n \\n \\n
\\n
\\n
\");\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 += \"
\\n

\".concat(category.title, \"

\\n
\");\n arrayItems.forEach(function (item) {\n if (item.category.toLowerCase() === category.title.toLowerCase()) {\n html += \"\\n
\\n
\\n
\\n \\\"#\\\"\\n
\\n \\n
\\n
\\n
\\n \").concat(diffDates(new Date(), new Date(item.date)), \"\\n
\\n
\\n \").concat(item.count, \" \\u0448\\u0442.\\n
\\n
\\n \\u0426\\u0435\\u043D\\u0430 \\u0437\\u0430 1 \\u0448\\u0442.\\n
\\n
\\n \").concat(item.price.toFixed(2), \"\\u20BD\\n
\\n
\\n \\n \\n
\\n
\\n
\");\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?"); /***/ }), diff --git a/dist/views/product.pug b/dist/views/product.pug index 112575b..7262bb2 100644 --- a/dist/views/product.pug +++ b/dist/views/product.pug @@ -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 diff --git a/src/js/templates/items.template.js b/src/js/templates/items.template.js index e7a114b..534fa8e 100644 --- a/src/js/templates/items.template.js +++ b/src/js/templates/items.template.js @@ -22,7 +22,7 @@ export function renderItems(categories, items) {
- ${item.date.split('T')[0]} + ${diffDates(new Date(), new Date(item.date))}
${item.count} шт. @@ -42,8 +42,14 @@ export function renderItems(categories, items) {
`; } }) - }); - return html; +} + +function diffDates(firstDate, secondDate) { + let diff = Math.floor((firstDate - secondDate) / (60 * 60 * 24 * 1000)); + if (diff <= 0) { + return 'добавлено сегодня'; + } + return diff + ' дней назад'; } \ No newline at end of file