Sorting & showing date
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import express from 'express'
|
||||
import bodyParser from 'body-parser';
|
||||
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
|
||||
var hr = require('date-fns/locale/hr');
|
||||
|
||||
var MongoClient = require('mongodb').MongoClient;
|
||||
var ObjectID = require('mongodb').ObjectID;
|
||||
|
||||
@@ -140,9 +143,22 @@ router.get('/search/listings', async (req, res, next) => {
|
||||
|
||||
res.header('X-Total-Count', cnt);
|
||||
|
||||
const getSort = () => {
|
||||
if (sort === 'price-min') {
|
||||
return [['price', 'asc']];
|
||||
} else if (sort === 'price-max') {
|
||||
return [['price', 'desc']];
|
||||
} else if (sort === 'newest') {
|
||||
return [['_id', 'desc']];
|
||||
} else if (sort === 'relevance') {
|
||||
// TODO: figure out what the relevance is
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
let all = properties.find(query, {
|
||||
//"sort": [['field1','asc'], ['field2','desc']]
|
||||
"sort": [['price','asc']]
|
||||
"sort": getSort()
|
||||
});
|
||||
|
||||
const isPins = pins === "true";
|
||||
@@ -179,7 +195,10 @@ router.get('/search/listings', async (req, res, next) => {
|
||||
price,
|
||||
rooms,
|
||||
size,
|
||||
time
|
||||
time: distanceInWordsToNow(
|
||||
new Date(time),
|
||||
{locale: hr}
|
||||
)
|
||||
})));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user