mirror of
https://github.com/sergeyyarkov/digital-store.git
synced 2026-10-11 18:29:11 +03:00
rename variables and parameters
This commit is contained in:
parent
18d3ca3021
commit
b5a6ba76c1
@ -1,9 +1,4 @@
|
|||||||
const db = require('../database');
|
function indexRoute(req, res, dbo) {
|
||||||
const dbName = db.name;
|
|
||||||
|
|
||||||
function indexRoute(req, res, db) {
|
|
||||||
const dbo = db.db(dbName);
|
|
||||||
|
|
||||||
dbo.collection('storeInfo').find().toArray((err, result) => {
|
dbo.collection('storeInfo').find().toArray((err, result) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
const array = Object.keys(result[0].items)
|
const array = Object.keys(result[0].items)
|
||||||
@ -17,12 +12,7 @@ function indexRoute(req, res, db) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getItemsRoute(req, res, db) {
|
function getItemsRoute(req, res, dbo) {
|
||||||
const dbo = db.db(dbName);
|
|
||||||
|
|
||||||
// установка кэша при отдачи json данных
|
|
||||||
//res.setHeader("Cache-Control", "public, max-age=20");
|
|
||||||
|
|
||||||
if (req.query.auth === 'yYNfW8ynVO18L1TW5qIkILM1WtWgrVZz') {
|
if (req.query.auth === 'yYNfW8ynVO18L1TW5qIkILM1WtWgrVZz') {
|
||||||
if (req.query.option === 'all' && !req.query.sorting) {
|
if (req.query.option === 'all' && !req.query.sorting) {
|
||||||
dbo.collection('storeInfo').find().toArray((err, result) => {
|
dbo.collection('storeInfo').find().toArray((err, result) => {
|
||||||
@ -48,14 +38,14 @@ function getItemsRoute(req, res, db) {
|
|||||||
dbo.collection('storeInfo').find().toArray((err, result) => {
|
dbo.collection('storeInfo').find().toArray((err, result) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
const items = result[0].items[req.query.category];
|
const items = result[0].items[req.query.category];
|
||||||
items.sort((a, b) => new Date(a.date) - new Date(b.date)); // фильтр по возрастанию пр дате
|
items.sort((a, b) => new Date(a.date) - new Date(b.date)); // фильтр по возрастанию по дате
|
||||||
res.send(items);
|
res.send(items);
|
||||||
});
|
});
|
||||||
} else if (!req.query.option && req.query.category && req.query.sorting === 'newer') {
|
} else if (!req.query.option && req.query.category && req.query.sorting === 'newer') {
|
||||||
dbo.collection('storeInfo').find().toArray((err, result) => {
|
dbo.collection('storeInfo').find().toArray((err, result) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
const items = result[0].items[req.query.category];
|
const items = result[0].items[req.query.category];
|
||||||
items.sort((a, b) => new Date(b.date) - new Date(a.date)) // фильтр по возрастанию пр дате
|
items.sort((a, b) => new Date(b.date) - new Date(a.date)) // фильтр по убыванию по дате
|
||||||
res.send(items);
|
res.send(items);
|
||||||
});
|
});
|
||||||
} else if (!req.query.option && req.query.category) {
|
} else if (!req.query.option && req.query.category) {
|
||||||
@ -104,9 +94,7 @@ function getItemsRoute(req, res, db) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onePageItemRoute(req, res, db) {
|
function onePageItemRoute(req, res, dbo) {
|
||||||
const dbo = db.db(dbName);
|
|
||||||
|
|
||||||
dbo.collection('storeInfo').find().toArray((err, result) => {
|
dbo.collection('storeInfo').find().toArray((err, result) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
const items = result[0].items;
|
const items = result[0].items;
|
||||||
@ -134,25 +122,25 @@ function onePageItemRoute(req, res, db) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function howToBuyRoute(req, res, db) {
|
function howToBuyRoute(req, res) {
|
||||||
res.render('how-to-buy', {
|
res.render('how-to-buy', {
|
||||||
pageName: 'how-to-buy'
|
pageName: 'how-to-buy'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function contactsRoute(req, res, db) {
|
function contactsRoute(req, res) {
|
||||||
res.render('contacts', {
|
res.render('contacts', {
|
||||||
pageName: 'contacts'
|
pageName: 'contacts'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function commentsRoute(req, res, db) {
|
function commentsRoute(req, res) {
|
||||||
res.render('comments', {
|
res.render('comments', {
|
||||||
pageName: 'comments'
|
pageName: 'comments'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function myOrdersRoute(req, res, db) {
|
function myOrdersRoute(req, res) {
|
||||||
res.render('my-orders', {
|
res.render('my-orders', {
|
||||||
pageName: 'my-orders'
|
pageName: 'my-orders'
|
||||||
});
|
});
|
||||||
@ -161,10 +149,10 @@ function myOrdersRoute(req, res, db) {
|
|||||||
|
|
||||||
module.exports = function (server, db) {
|
module.exports = function (server, db) {
|
||||||
server.get('/', (req, res) => indexRoute(req, res, db));
|
server.get('/', (req, res) => indexRoute(req, res, db));
|
||||||
|
server.get('/store-api', (req, res) => getItemsRoute(req, res, db));
|
||||||
server.get('/how-to-buy', (req, res) => howToBuyRoute(req, res, db));
|
server.get('/how-to-buy', (req, res) => howToBuyRoute(req, res, db));
|
||||||
server.get('/contacts', (req, res) => contactsRoute(req, res, db));
|
server.get('/contacts', (req, res) => contactsRoute(req, res, db));
|
||||||
server.get('/comments', (req, res) => commentsRoute(req, res, db));
|
server.get('/comments', (req, res) => commentsRoute(req, res, db));
|
||||||
server.get('/my-orders', (req, res) => myOrdersRoute(req, res, db));
|
server.get('/my-orders', (req, res) => myOrdersRoute(req, res, db));
|
||||||
server.get('/product/:id', (req, res) => onePageItemRoute(req, res, db));
|
server.get('/product/:id', (req, res) => onePageItemRoute(req, res, db));
|
||||||
server.get('/store-api', (req, res) => getItemsRoute(req, res, db));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,23 +1,21 @@
|
|||||||
const MongoClient = require('mongodb').MongoClient;
|
const MongoClient = require('mongodb').MongoClient;
|
||||||
const db = require('./database');
|
const db_config = require('./database');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const server = express();
|
const server = express();
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
MongoClient.connect(db_config.url, {useNewUrlParser: true, useUnifiedTopology: true}, (err, client) => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MongoClient.connect(db.url, {useNewUrlParser: true, useUnifiedTopology: true}, (err, database) => {
|
|
||||||
if (err) return console.log(err)
|
if (err) return console.log(err)
|
||||||
|
const db = client.db(db_config.name);
|
||||||
|
|
||||||
// Pug config
|
// Config
|
||||||
server.use(express.static(path.join(__dirname, '../dist/public')));
|
server.use(express.static(path.join(__dirname, '../dist/public')));
|
||||||
// server.use('/css', express.static(__dirname + '../dist/public/css'));
|
|
||||||
server.set('view engine', 'pug');
|
server.set('view engine', 'pug');
|
||||||
server.set('views', path.join(__dirname, '../dist/views'));
|
server.set('views', path.join(__dirname, '../dist/views'));
|
||||||
|
|
||||||
require('./routes/routes')(server, database);
|
// Routes
|
||||||
|
require('./routes/routes')(server, db);
|
||||||
|
|
||||||
// 404 Redirect
|
// 404 Redirect
|
||||||
server.use((req, res) => res.status(404).send('Error 404'));
|
server.use((req, res) => res.status(404).send('Error 404'));
|
||||||
server.listen(3000, () => console.log('Listen port 3000...'));
|
server.listen(3000, () => console.log('Listen port 3000...'));
|
||||||
|
|||||||
4
dist/public/js/bundle.js
vendored
4
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__) {
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
||||||
|
|
||||||
"use strict";
|
"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 html = '';\n categories.forEach(function (category) {\n html += \"<div class=\\\"items-category\\\">\\n <h2 class=\\\"small-title\\\">\".concat(category, \"</h2>\\n </div>\");\n items[category].forEach(function (item) {\n if (item) {\n html += \"\\n <div class=\\\"items-list\\\">\\n <div class=\\\"items-list__name\\\">\\n <div class=\\\"list-icon\\\">\\n <img src=\\\"./img/service-icons/\".concat(item.image, \"\\\" 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, \"</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 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 } else {\n html += \"\\n <div class=\\\"items-list\\\">\\n <div class=\\\"items-list__name\\\">\\n <div class=\\\"list-title\\\">\\n <span>\\u0412 \\u044D\\u0442\\u043E\\u0439 \\u043A\\u0430\\u0442\\u0435\\u0433\\u043E\\u0440\\u0438\\u0438 \\u043F\\u043E\\u043A\\u0430 \\u0447\\u0442\\u043E \\u043D\\u0435\\u0442\\u0443 \\u0442\\u043E\\u0432\\u0430\\u0440\\u043E\\u0432</span>\\n </div>\\n </div>\\n </div>\\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 html = '';\n categories.forEach(function (category) {\n html += \"<div class=\\\"items-category\\\">\\n <h2 class=\\\"small-title\\\">\".concat(category, \"</h2>\\n </div>\");\n items[category].forEach(function (item) {\n if (item && item._id != undefined) {\n html += \"\\n <div class=\\\"items-list\\\">\\n <div class=\\\"items-list__name\\\">\\n <div class=\\\"list-icon\\\">\\n <img src=\\\"./img/service-icons/\".concat(item.image, \"\\\" 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, \"</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 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 } else {\n html += \"\\n <div class=\\\"items-list\\\">\\n <div class=\\\"items-list__name\\\">\\n <div class=\\\"list-title\\\">\\n <span>\\u0412 \\u044D\\u0442\\u043E\\u0439 \\u043A\\u0430\\u0442\\u0435\\u0433\\u043E\\u0440\\u0438\\u0438 \\u043F\\u043E\\u043A\\u0430 \\u0447\\u0442\\u043E \\u043D\\u0435\\u0442\\u0443 \\u0442\\u043E\\u0432\\u0430\\u0440\\u043E\\u0432</span>\\n </div>\\n </div>\\n </div>\\n \";\n }\n });\n });\n return html;\n}\n\n//# sourceURL=webpack:///./src/js/templates/items.template.js?");
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
@ -4062,7 +4062,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) *
|
|||||||
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"renderItemsOne\", function() { return renderItemsOne; });\nfunction renderItemsOne(category, items) {\n var html = '';\n html += \"<div class=\\\"items-category\\\">\\n <h2 class=\\\"small-title\\\">\".concat(category, \"</h2>\\n </div>\");\n items.forEach(function (item) {\n if (item) {\n html += \"\\n <div class=\\\"items-list\\\">\\n <div class=\\\"items-list__name\\\">\\n <div class=\\\"list-icon\\\">\\n <img src=\\\"./img/service-icons/\".concat(item.image, \"\\\" 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, \"</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 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 } else {\n html += \"\\n <div class=\\\"items-list\\\">\\n <div class=\\\"items-list__name\\\">\\n <div class=\\\"list-title\\\">\\n <span>\\u0412 \\u044D\\u0442\\u043E\\u0439 \\u043A\\u0430\\u0442\\u0435\\u0433\\u043E\\u0440\\u0438\\u0438 \\u043F\\u043E\\u043A\\u0430 \\u0447\\u0442\\u043E \\u043D\\u0435\\u0442\\u0443 \\u0442\\u043E\\u0432\\u0430\\u0440\\u043E\\u0432</span>\\n </div>\\n </div>\\n </div>\";\n }\n });\n return html;\n}\n\n//# sourceURL=webpack:///./src/js/templates/itemsOne.template.js?");
|
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"renderItemsOne\", function() { return renderItemsOne; });\nfunction renderItemsOne(category, items) {\n var html = '';\n html += \"<div class=\\\"items-category\\\">\\n <h2 class=\\\"small-title\\\">\".concat(category, \"</h2>\\n </div>\");\n items.forEach(function (item) {\n if (item && item._id != undefined) {\n html += \"\\n <div class=\\\"items-list\\\">\\n <div class=\\\"items-list__name\\\">\\n <div class=\\\"list-icon\\\">\\n <img src=\\\"./img/service-icons/\".concat(item.image, \"\\\" 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, \"</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 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 } else {\n html += \"\\n <div class=\\\"items-list\\\">\\n <div class=\\\"items-list__name\\\">\\n <div class=\\\"list-title\\\">\\n <span>\\u0412 \\u044D\\u0442\\u043E\\u0439 \\u043A\\u0430\\u0442\\u0435\\u0433\\u043E\\u0440\\u0438\\u0438 \\u043F\\u043E\\u043A\\u0430 \\u0447\\u0442\\u043E \\u043D\\u0435\\u0442\\u0443 \\u0442\\u043E\\u0432\\u0430\\u0440\\u043E\\u0432</span>\\n </div>\\n </div>\\n </div>\";\n }\n });\n return html;\n}\n\n//# sourceURL=webpack:///./src/js/templates/itemsOne.template.js?");
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ export function renderItems(categories, items) {
|
|||||||
<h2 class="small-title">${category}</h2>
|
<h2 class="small-title">${category}</h2>
|
||||||
</div>`;
|
</div>`;
|
||||||
items[category].forEach(item => {
|
items[category].forEach(item => {
|
||||||
if (item) {
|
if (item && item._id != undefined) {
|
||||||
html += `
|
html += `
|
||||||
<div class="items-list">
|
<div class="items-list">
|
||||||
<div class="items-list__name">
|
<div class="items-list__name">
|
||||||
|
|||||||
@ -6,7 +6,7 @@ export function renderItemsOne(category, items) {
|
|||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
if (item) {
|
if (item && item._id != undefined) {
|
||||||
html += `
|
html += `
|
||||||
<div class="items-list">
|
<div class="items-list">
|
||||||
<div class="items-list__name">
|
<div class="items-list__name">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user