crawler upgrade, server upgrade

This commit is contained in:
GotPPay
2017-10-30 22:54:56 +01:00
parent 039e34237d
commit a63c108259
14 changed files with 8757 additions and 2517 deletions

View File

@@ -4,6 +4,12 @@ import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
import parseDate from 'date-fns/format';
import moment from 'moment';
import {
STATUS_NORMAL,
STATUS_RESERVED,
STATUS_SOLD
} from "./enums";
var hr = require('date-fns/locale/hr');
var MongoClient = require('mongodb').MongoClient;
@@ -78,6 +84,7 @@ router.get('/search/listings/:id', async (req, res, next) => {
router.get('/search/listings', async (req, res, next) => {
try {
console.log("Search listings");
const bounds = req.query.bounds || '';
const minPrice = req.query.minPrice;
const maxPrice = req.query.maxPrice;
@@ -93,6 +100,22 @@ router.get('/search/listings', async (req, res, next) => {
const properties = db.collection('listings');
let query = {};
//Get only ads with location
query = Object.assign(query, {
has_map: true
});
//AND
//Do not show sold or reserved properity
query = Object.assign(query, {
status: STATUS_NORMAL
});
//AND
//Show ads that fall inside visible map
if (bounds) {
const [lat1, lng1, lat2, lng2] = bounds.split(',').map(parseFloat)
const box = [[lat1, lng1], [lat2, lng2]];
@@ -106,12 +129,18 @@ router.get('/search/listings', async (req, res, next) => {
});
}
//AND
//Show only selected type of ads (selling or renting)
if (adType) {
query = Object.assign(query, {
adType: parseInt(adType)
});
}
//AND
//Match price
if (minPrice || maxPrice) {
const price = {}
if (minPrice) {
@@ -127,25 +156,37 @@ router.get('/search/listings', async (req, res, next) => {
});
}
const and = [];
//AND
//Match number of rooms
if (rooms) {
const room_count = [];
let four_plus = false;
const allRooms = rooms.split(',');
const or = allRooms.map(val => {
if (val === '4+') {
return {
rooms: {
"$gte": 4
}
}
allRooms.map((val)=>{
if (parseInt(val)!==4){
room_count.push(parseInt(val));
}else{
four_plus=true;
}
return {
rooms: parseFloat(val)
};
});
and.push({ "$or": or });
if (four_plus){
query = Object.assign(query,{
rooms: {'$gte' : 4}
});
}else{
query = Object.assign(query,{
rooms: {'$in' : room_count}
});
}
}
//AND
//Match size
if (minSize || maxSize) {
const size = {}
if (minSize) {
@@ -161,21 +202,21 @@ router.get('/search/listings', async (req, res, next) => {
});
}
//AND
//Match category
if (category) {
const allCategories = category.split(',');
const or = allCategories.map(val => {
return {
category: parseInt(val)
};
const category_count = [];
const allCategories = category.split(',').map(val => {
category_count.push(parseInt(val));
});
and.push({ "$or": or });
}
if (and.length > 0) {
query = Object.assign(query, {
"$and": and
category: {'$in' : category_count}
});
}
console.log('QUERY: ', query);