crawler upgrade, server upgrade
This commit is contained in:
File diff suppressed because it is too large
Load Diff
16
backend/enums.js
Normal file
16
backend/enums.js
Normal file
@@ -0,0 +1,16 @@
|
||||
export const AD_TYPE_SALE = 1;
|
||||
export const AD_TYPE_RENT = 2;
|
||||
|
||||
export const IGNORED_USERNAMES = ['rental']
|
||||
|
||||
export const CATEGORY_FLAT = 0;
|
||||
export const CATEGORY_HOUSE = 1;
|
||||
export const CATEGORY_OFFICE = 2;
|
||||
export const CATEGORY_LAND = 3;
|
||||
export const CATEGORY_APARTMENT = 4;
|
||||
export const CATEGORY_GARAGE = 5;
|
||||
|
||||
export const STATUS_NORMAL = 0;
|
||||
export const STATUS_RESERVED = 1;
|
||||
export const STATUS_SOLD = 2;
|
||||
|
||||
1441
backend/package-lock.json
generated
Normal file
1441
backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user