Sorting & showing date
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,7 @@
|
||||
"babel-preset-es2017": "^6.22.0",
|
||||
"body-parser": "^1.17.1",
|
||||
"cookie-parser": "^1.4.3",
|
||||
"date-fns": "^1.28.2",
|
||||
"express": "^4.15.2",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"mongodb": "^2.2.25"
|
||||
|
||||
@@ -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}
|
||||
)
|
||||
})));
|
||||
}
|
||||
|
||||
|
||||
@@ -562,6 +562,10 @@ core-util-is@~1.0.0:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
|
||||
|
||||
date-fns:
|
||||
version "1.28.2"
|
||||
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-1.28.2.tgz#19e4192d68875c0bf7c9537e3f296a8ec64853ef"
|
||||
|
||||
debug@^2.1.1, debug@^2.2.0, debug@2.6.3:
|
||||
version "2.6.3"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.3.tgz#0f7eb8c30965ec08c72accfa0130c8b79984141d"
|
||||
|
||||
Reference in New Issue
Block a user