Fix for empty filter parameters
This commit is contained in:
parent
5bae041381
commit
c493af392c
@ -79,7 +79,7 @@ router.get('/brands', async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
let collection = req.db.collection('vehicles');
|
let collection = req.db.collection('vehicles');
|
||||||
let brands = await collection.distinct('brand.name.normalized');
|
let brands = await collection.distinct('brand.name.normalized');
|
||||||
res.send({ success: true, data: brands });
|
res.send({ success: true, data: brands.filter(Boolean) });
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
res.send(makeError('Error reading vehicle brands from DB'));
|
res.send(makeError('Error reading vehicle brands from DB'));
|
||||||
console.error(ex);
|
console.error(ex);
|
||||||
@ -91,7 +91,7 @@ router.get('/models', async (req, res) => {
|
|||||||
const { brand } = req.query;
|
const { brand } = req.query;
|
||||||
let collection = req.db.collection('vehicles');
|
let collection = req.db.collection('vehicles');
|
||||||
let models = await collection.distinct('model.name.normalized', { 'brand.name.normalized': brand });
|
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) {
|
} catch(ex) {
|
||||||
res.send(makeError('Error reading vehicle models from DB'));
|
res.send(makeError('Error reading vehicle models from DB'));
|
||||||
console.error(ex);
|
console.error(ex);
|
||||||
@ -102,7 +102,7 @@ router.get('/colors', async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
let collection = req.db.collection('vehicles');
|
let collection = req.db.collection('vehicles');
|
||||||
let colors = await collection.distinct('color');
|
let colors = await collection.distinct('color');
|
||||||
res.send({ success: true, data: colors });
|
res.send({ success: true, data: colors.filter(Boolean) });
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
res.send(makeError('Error reading vehicle colors from DB'));
|
res.send(makeError('Error reading vehicle colors from DB'));
|
||||||
console.error(ex);
|
console.error(ex);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user