Sorting & showing date

This commit is contained in:
Edin Dazdarevic
2017-04-08 02:11:54 +02:00
parent ffdf1d36b3
commit 027323919e
8 changed files with 1559 additions and 67 deletions

View File

@@ -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}
)
})));
}