new structure; code polish

This commit is contained in:
GotPPay
2017-10-31 20:20:09 +01:00
parent a63c108259
commit 7a5f7242ac
25 changed files with 1670 additions and 6108 deletions

View File

@@ -726,7 +726,7 @@ router.get('/search/listings/:id', function () {
router.get('/search/listings', function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(req, res, next) {
var bounds, minPrice, maxPrice, minSize, maxSize, rooms, adType, category, sort, page, pins, properties, query, _bounds$split$map, _bounds$split$map2, lat1, lng1, lat2, lng2, box, price, room_count, four_plus, allRooms, size, category_count, allCategories, cnt, getSort, all, isPins;
var bounds, minPrice, maxPrice, minSize, maxSize, rooms, adType, category, sort, page, pins, properties, query, _bounds$split$map, _bounds$split$map2, lat1, lng1, lat2, lng2, box, price, roomCount, fourPlus, allRooms, size, categoryCount, allCategories, cnt, getSort, all, isPins;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
@@ -734,7 +734,7 @@ router.get('/search/listings', function () {
case 0:
_context3.prev = 0;
console.log("Search listings");
console.log('Search listings');
bounds = req.query.bounds || '';
minPrice = req.query.minPrice;
maxPrice = req.query.maxPrice;
@@ -772,8 +772,8 @@ router.get('/search/listings', function () {
query = Object.assign(query, {
loc: {
"$geoWithin": {
"$box": box
$geoWithin: {
$box: box
}
}
});
@@ -795,11 +795,11 @@ router.get('/search/listings', function () {
price = {};
if (minPrice) {
price["$gte"] = parseFloat(minPrice);
price['$gte'] = parseFloat(minPrice);
}
if (maxPrice) {
price["$lte"] = parseFloat(maxPrice);
price['$lte'] = parseFloat(maxPrice);
}
query = Object.assign(query, {
@@ -811,42 +811,41 @@ router.get('/search/listings', function () {
//Match number of rooms
if (rooms) {
room_count = [];
four_plus = false;
roomCount = [];
fourPlus = false;
allRooms = rooms.split(',');
allRooms.map(function (val) {
if (parseInt(val) !== 4) {
room_count.push(parseInt(val));
roomCount.push(parseInt(val));
} else {
four_plus = true;
fourPlus = true;
}
});
if (four_plus) {
if (fourPlus) {
query = Object.assign(query, {
rooms: { '$gte': 4 }
rooms: { $gte: 4 }
});
} else {
query = Object.assign(query, {
rooms: { '$in': room_count }
rooms: { $in: roomCount }
});
}
}
//AND
//Match size
if (minSize || maxSize) {
size = {};
if (minSize) {
size["$gte"] = parseFloat(minSize);
size['$gte'] = parseFloat(minSize);
}
if (maxSize) {
size["$lte"] = parseFloat(maxSize);
size['$lte'] = parseFloat(maxSize);
}
query = Object.assign(query, {
@@ -858,14 +857,14 @@ router.get('/search/listings', function () {
//Match category
if (category) {
category_count = [];
categoryCount = [];
allCategories = category.split(',').map(function (val) {
category_count.push(parseInt(val));
categoryCount.push(parseInt(val));
});
query = Object.assign(query, {
category: { '$in': category_count }
category: { $in: categoryCount }
});
}
@@ -894,9 +893,9 @@ router.get('/search/listings', function () {
all = properties.find(query, {
//"sort": [['field1','asc'], ['field2','desc']]
"sort": getSort()
sort: getSort()
});
isPins = pins === "true";
isPins = pins === 'true';
if (isPins) {
_context3.next = 37;
@@ -932,7 +931,6 @@ router.get('/search/listings', function () {
};
}));
} else {
res.json(all.map(function (_ref4) {
var _id = _ref4._id,
address = _ref4.address,
@@ -948,7 +946,9 @@ router.get('/search/listings', function () {
price: price,
rooms: rooms,
size: size,
time: (0, _distance_in_words_to_now2.default)((0, _moment2.default)(time, 'DD.MM.YYYY'), { locale: hr }),
time: (0, _distance_in_words_to_now2.default)((0, _moment2.default)(time, 'DD.MM.YYYY'), {
locale: hr
}),
realTime: time
};
}));
@@ -982,10 +982,10 @@ var app = (0, _express2.default)();
app.use(_bodyParser2.default.json());
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, X-Last-Record-Id, X-Total-Count");
res.header("Access-Control-Expose-Headers", "X-Last-Record-Id, X-Total-Count");
res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, X-Last-Record-Id, X-Total-Count');
res.header('Access-Control-Expose-Headers', 'X-Last-Record-Id, X-Total-Count');
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
res.header('Access-Control-Allow-Credentials', 'true');
next();
});
@@ -994,7 +994,7 @@ app.use('/api', router);
MongoClient.connect(url).then(function (database) {
db = database;
db.collection('listings').createIndex({ loc: "2d" });
db.collection('listings').createIndex({ loc: '2d' });
app.listen(PORT, function () {
return console.log('Express server running at localhost: ' + PORT);
});