mirror of
https://github.com/sergeyyarkov/digital-store.git
synced 2026-10-11 10:19:15 +03:00
Component Filter 'not refactored'
This commit is contained in:
parent
d6207e7dde
commit
e86ed640f9
@ -44,6 +44,20 @@ function getItemsRoute(req, res, db) {
|
|||||||
items.sort((a, b) => b.price - a.price) // фильтр по убыванию по цене
|
items.sort((a, b) => b.price - a.price) // фильтр по убыванию по цене
|
||||||
res.send(items);
|
res.send(items);
|
||||||
});
|
});
|
||||||
|
} else if (!req.query.option && req.query.category && req.query.sorting === 'older') {
|
||||||
|
dbo.collection('storeInfo').find().toArray((err, result) => {
|
||||||
|
if (err) throw err;
|
||||||
|
const items = result[0].items[req.query.category];
|
||||||
|
items.sort((a, b) => new Date(a.date) - new Date(b.date)); // фильтр по возрастанию пр дате
|
||||||
|
res.send(items);
|
||||||
|
});
|
||||||
|
} else if (!req.query.option && req.query.category && req.query.sorting === 'newer') {
|
||||||
|
dbo.collection('storeInfo').find().toArray((err, result) => {
|
||||||
|
if (err) throw err;
|
||||||
|
const items = result[0].items[req.query.category];
|
||||||
|
items.sort((a, b) => new Date(b.date) - new Date(a.date)) // фильтр по возрастанию пр дате
|
||||||
|
res.send(items);
|
||||||
|
});
|
||||||
} else if (!req.query.option && req.query.category) {
|
} else if (!req.query.option && req.query.category) {
|
||||||
dbo.collection('storeInfo').find().toArray((err, result) => {
|
dbo.collection('storeInfo').find().toArray((err, result) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -68,6 +82,20 @@ function getItemsRoute(req, res, db) {
|
|||||||
Object.values(items).forEach(arr => arr.sort((a, b) => b.price - a.price)) // фильтр по убыванию по цене
|
Object.values(items).forEach(arr => arr.sort((a, b) => b.price - a.price)) // фильтр по убыванию по цене
|
||||||
res.send(items);
|
res.send(items);
|
||||||
})
|
})
|
||||||
|
} else if (req.query.option && req.query.sorting === 'older') {
|
||||||
|
dbo.collection('storeInfo').find().toArray((err, result) => {
|
||||||
|
if (err) throw err;
|
||||||
|
const items = result[0].items;
|
||||||
|
Object.values(items).forEach(arr => arr.sort((a, b) => new Date(a.date) - new Date(b.date))) // фильтр по возрастанию пр дате
|
||||||
|
res.send(items);
|
||||||
|
});
|
||||||
|
} else if (req.query.option && req.query.sorting === 'newer') {
|
||||||
|
dbo.collection('storeInfo').find().toArray((err, result) => {
|
||||||
|
if (err) throw err;
|
||||||
|
const items = result[0].items;
|
||||||
|
Object.values(items).forEach(arr => arr.sort((a, b) => new Date(b.date) - new Date(a.date))) // фильтр по возрастанию пр дате
|
||||||
|
res.send(items);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
res.send('Запрос неверный');
|
res.send('Запрос неверный');
|
||||||
}
|
}
|
||||||
@ -95,7 +123,8 @@ function onePageItemRoute(req, res, db) {
|
|||||||
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: item.description,
|
||||||
|
date: item.date
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
dist/public/js/bundle.js
vendored
6
dist/public/js/bundle.js
vendored
File diff suppressed because one or more lines are too long
2
dist/views/product.pug
vendored
2
dist/views/product.pug
vendored
@ -22,6 +22,8 @@ main.main-section
|
|||||||
hr
|
hr
|
||||||
.product-title.block-title
|
.product-title.block-title
|
||||||
h1 #{title}
|
h1 #{title}
|
||||||
|
br
|
||||||
|
small(style="font-size: 12px") Дата добавления: #{date}
|
||||||
.product-info
|
.product-info
|
||||||
.product-info__left
|
.product-info__left
|
||||||
.product-left__pay
|
.product-left__pay
|
||||||
|
|||||||
@ -23,7 +23,7 @@ export class CategoryComponent extends Component {
|
|||||||
document.querySelector('#loader').classList.add('hide');
|
document.querySelector('#loader').classList.add('hide');
|
||||||
bounded(category); // <- ф-я окраски li по нажатию на breadcrumb
|
bounded(category); // <- ф-я окраски li по нажатию на breadcrumb
|
||||||
|
|
||||||
// отображем данные если был нажат breadcrumb
|
// отображем айтемсы если был нажат breadcrumb
|
||||||
(async function(){
|
(async function(){
|
||||||
const fData = await apiService.getItemsOne(category),
|
const fData = await apiService.getItemsOne(category),
|
||||||
html = renderItemsOne(category, fData);
|
html = renderItemsOne(category, fData);
|
||||||
|
|||||||
@ -19,6 +19,9 @@ export function renderItems(categories, items) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="items-list__info">
|
<div class="items-list__info">
|
||||||
|
<div class="list-date">
|
||||||
|
<small>${item.date}</small>
|
||||||
|
</div>
|
||||||
<div class="list-count">
|
<div class="list-count">
|
||||||
<span>${item.count} шт.</span>
|
<span>${item.count} шт.</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -18,6 +18,9 @@ export function renderItemsOne(category, items) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="items-list__info">
|
<div class="items-list__info">
|
||||||
|
<div class="list-date">
|
||||||
|
<small>${item.date}</small>
|
||||||
|
</div>
|
||||||
<div class="list-count">
|
<div class="list-count">
|
||||||
<span>${item.count} шт.</span>
|
<span>${item.count} шт.</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user