Load listing details from the server
This commit is contained in:
@@ -76,15 +76,61 @@
|
||||
|
||||
var db = void 0;
|
||||
|
||||
router.get('/search/listings', function () {
|
||||
router.get('/search/listings/:id', function () {
|
||||
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(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, and, allRooms, or, size, allCategories, _or, cnt, all;
|
||||
|
||||
var id, listings, listing;
|
||||
return regeneratorRuntime.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
case 0:
|
||||
_context.prev = 0;
|
||||
id = req.params.id;
|
||||
listings = db.collection('listings');
|
||||
_context.next = 5;
|
||||
return listings.findOne({ _id: new ObjectID(id) });
|
||||
|
||||
case 5:
|
||||
listing = _context.sent;
|
||||
|
||||
if (listing) {
|
||||
res.json(listing);
|
||||
} else {
|
||||
res.status(404);
|
||||
}
|
||||
|
||||
res.end();
|
||||
_context.next = 14;
|
||||
break;
|
||||
|
||||
case 10:
|
||||
_context.prev = 10;
|
||||
_context.t0 = _context['catch'](0);
|
||||
|
||||
console.log('error:', _context.t0);
|
||||
next(_context.t0);
|
||||
|
||||
case 14:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, undefined, [[0, 10]]);
|
||||
}));
|
||||
|
||||
return function (_x, _x2, _x3) {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
}());
|
||||
|
||||
router.get('/search/listings', function () {
|
||||
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2(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, and, allRooms, or, size, allCategories, _or, cnt, all, isPins;
|
||||
|
||||
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
||||
while (1) {
|
||||
switch (_context2.prev = _context2.next) {
|
||||
case 0:
|
||||
_context2.prev = 0;
|
||||
bounds = req.query.bounds || '';
|
||||
minPrice = req.query.minPrice;
|
||||
maxPrice = req.query.maxPrice;
|
||||
@@ -192,11 +238,11 @@
|
||||
}
|
||||
|
||||
console.log('QUERY: ', query);
|
||||
_context.next = 25;
|
||||
_context2.next = 25;
|
||||
return properties.find(query).count();
|
||||
|
||||
case 25:
|
||||
cnt = _context.sent;
|
||||
cnt = _context2.sent;
|
||||
|
||||
|
||||
res.header('X-Total-Count', cnt);
|
||||
@@ -205,55 +251,83 @@
|
||||
//"sort": [['field1','asc'], ['field2','desc']]
|
||||
"sort": [['price', 'asc']]
|
||||
});
|
||||
isPins = pins === "true";
|
||||
|
||||
if (!(pins !== "true")) {
|
||||
_context.next = 34;
|
||||
if (isPins) {
|
||||
_context2.next = 35;
|
||||
break;
|
||||
}
|
||||
|
||||
_context.next = 31;
|
||||
_context2.next = 32;
|
||||
return all.skip(20 * page).limit(20).toArray();
|
||||
|
||||
case 31:
|
||||
all = _context.sent;
|
||||
_context.next = 37;
|
||||
case 32:
|
||||
all = _context2.sent;
|
||||
_context2.next = 38;
|
||||
break;
|
||||
|
||||
case 34:
|
||||
_context.next = 36;
|
||||
case 35:
|
||||
_context2.next = 37;
|
||||
return all.toArray();
|
||||
|
||||
case 36:
|
||||
all = _context.sent;
|
||||
|
||||
case 37:
|
||||
all = _context2.sent;
|
||||
|
||||
case 38:
|
||||
|
||||
if (all.length > 0) {
|
||||
res.header('X-Last-Record-Id', [].concat(_toConsumableArray(all)).pop()._id);
|
||||
}
|
||||
|
||||
res.json(all);
|
||||
if (isPins) {
|
||||
res.json(all.map(function (val) {
|
||||
return {
|
||||
_id: val._id,
|
||||
loc: val.loc
|
||||
};
|
||||
}));
|
||||
} else {
|
||||
res.json(all.map(function (_ref3) {
|
||||
var _id = _ref3._id,
|
||||
address = _ref3.address,
|
||||
images = _ref3.images,
|
||||
price = _ref3.price,
|
||||
rooms = _ref3.rooms,
|
||||
size = _ref3.size,
|
||||
time = _ref3.time;
|
||||
return {
|
||||
_id: _id,
|
||||
address: address,
|
||||
images: [images[0]],
|
||||
price: price,
|
||||
rooms: rooms,
|
||||
size: size,
|
||||
time: time
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
res.end();
|
||||
_context.next = 46;
|
||||
_context2.next = 47;
|
||||
break;
|
||||
|
||||
case 42:
|
||||
_context.prev = 42;
|
||||
_context.t0 = _context['catch'](0);
|
||||
case 43:
|
||||
_context2.prev = 43;
|
||||
_context2.t0 = _context2['catch'](0);
|
||||
|
||||
console.log('error:', _context.t0);
|
||||
next(_context.t0);
|
||||
console.log('error:', _context2.t0);
|
||||
next(_context2.t0);
|
||||
|
||||
case 46:
|
||||
case 47:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
return _context2.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, undefined, [[0, 42]]);
|
||||
}, _callee2, undefined, [[0, 43]]);
|
||||
}));
|
||||
|
||||
return function (_x, _x2, _x3) {
|
||||
return _ref.apply(this, arguments);
|
||||
return function (_x4, _x5, _x6) {
|
||||
return _ref2.apply(this, arguments);
|
||||
};
|
||||
}());
|
||||
|
||||
|
||||
@@ -14,6 +14,25 @@ const AGENTURA_KEY = process.env.AGENTURA_KEY || '1somethingverysecret';
|
||||
|
||||
let db;
|
||||
|
||||
router.get('/search/listings/:id', async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
|
||||
const listings = db.collection('listings');
|
||||
const listing = await listings.findOne({_id: new ObjectID(id)});
|
||||
if (listing) {
|
||||
res.json(listing);
|
||||
} else {
|
||||
res.status(404);
|
||||
}
|
||||
|
||||
res.end();
|
||||
} catch (e) {
|
||||
console.log('error:', e);
|
||||
next(e);
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/search/listings', async (req, res, next) => {
|
||||
try {
|
||||
const bounds = req.query.bounds || '';
|
||||
@@ -126,7 +145,9 @@ router.get('/search/listings', async (req, res, next) => {
|
||||
"sort": [['price','asc']]
|
||||
});
|
||||
|
||||
if (pins !== "true") {
|
||||
const isPins = pins === "true";
|
||||
|
||||
if (!isPins) {
|
||||
all = await all.skip(20 * page).limit(20).toArray();
|
||||
} else {
|
||||
all = await all.toArray();
|
||||
@@ -136,7 +157,32 @@ router.get('/search/listings', async (req, res, next) => {
|
||||
res.header('X-Last-Record-Id', [...all].pop()._id);
|
||||
}
|
||||
|
||||
res.json(all);
|
||||
if (isPins) {
|
||||
res.json(all.map(val => {
|
||||
return {
|
||||
_id: val._id,
|
||||
loc: val.loc
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
res.json(all.map(({_id,
|
||||
address,
|
||||
images,
|
||||
price,
|
||||
rooms,
|
||||
size,
|
||||
time
|
||||
}) => ({
|
||||
_id,
|
||||
address,
|
||||
images: [images[0]],
|
||||
price,
|
||||
rooms,
|
||||
size,
|
||||
time
|
||||
})));
|
||||
}
|
||||
|
||||
res.end();
|
||||
} catch (e) {
|
||||
console.log('error:', e);
|
||||
|
||||
Reference in New Issue
Block a user