Fix for empty filter parameters

This commit is contained in:
Selim Mustafaev 2020-06-18 17:51:25 +03:00
parent 5bae041381
commit c493af392c

View File

@ -79,7 +79,7 @@ router.get('/brands', async (req, res) => {
try {
let collection = req.db.collection('vehicles');
let brands = await collection.distinct('brand.name.normalized');
res.send({ success: true, data: brands });
res.send({ success: true, data: brands.filter(Boolean) });
} catch(ex) {
res.send(makeError('Error reading vehicle brands from DB'));
console.error(ex);
@ -91,7 +91,7 @@ router.get('/models', async (req, res) => {
const { brand } = req.query;
let collection = req.db.collection('vehicles');
let models = await collection.distinct('model.name.normalized', { 'brand.name.normalized': brand });
res.send({ success: true, data: models });
res.send({ success: true, data: models.filter(Boolean) });
} catch(ex) {
res.send(makeError('Error reading vehicle models from DB'));
console.error(ex);
@ -102,7 +102,7 @@ router.get('/colors', async (req, res) => {
try {
let collection = req.db.collection('vehicles');
let colors = await collection.distinct('color');
res.send({ success: true, data: colors });
res.send({ success: true, data: colors.filter(Boolean) });
} catch(ex) {
res.send(makeError('Error reading vehicle colors from DB'));
console.error(ex);