Load listing details from the server
This commit is contained in:
@@ -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