Component Filter 'not refactored'

This commit is contained in:
Sergey Yarkov 2019-11-21 21:23:06 +03:00
parent d6207e7dde
commit e86ed640f9
6 changed files with 42 additions and 5 deletions

View File

@ -44,6 +44,20 @@ function getItemsRoute(req, res, db) {
items.sort((a, b) => b.price - a.price) // фильтр по убыванию по цене
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) {
dbo.collection('storeInfo').find().toArray((err, result) => {
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)) // фильтр по убыванию по цене
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 {
res.send('Запрос неверный');
}
@ -95,7 +123,8 @@ function onePageItemRoute(req, res, db) {
count: item.count,
category: item.category[0].toUpperCase() + item.category.slice(1),
price: item.price,
description: item.description
description: item.description,
date: item.date
});
}
}

File diff suppressed because one or more lines are too long

View File

@ -22,6 +22,8 @@ main.main-section
hr
.product-title.block-title
h1 #{title}
br
small(style="font-size: 12px") Дата добавления: #{date}
.product-info
.product-info__left
.product-left__pay

View File

@ -23,7 +23,7 @@ export class CategoryComponent extends Component {
document.querySelector('#loader').classList.add('hide');
bounded(category); // <- ф-я окраски li по нажатию на breadcrumb
// отображем данные если был нажат breadcrumb
// отображем айтемсы если был нажат breadcrumb
(async function(){
const fData = await apiService.getItemsOne(category),
html = renderItemsOne(category, fData);

View File

@ -19,6 +19,9 @@ export function renderItems(categories, items) {
</div>
</div>
<div class="items-list__info">
<div class="list-date">
<small>${item.date}</small>
</div>
<div class="list-count">
<span>${item.count} шт.</span>
</div>

View File

@ -18,6 +18,9 @@ export function renderItemsOne(category, items) {
</div>
</div>
<div class="items-list__info">
<div class="list-date">
<small>${item.date}</small>
</div>
<div class="list-count">
<span>${item.count} шт.</span>
</div>