// routes/ad
router.get("/ads-for-sell", ad.adsForSell);
router.get("/ads-for-rent", ad.adsForRent);
// controllers/ad
export const adsForSell = async (req, res) => {
try {
const ads = await Ad.find({ action: "Sell", published: true })
.select(
"-photos.Key -photos.key -photos.ETag -photos.Bucket -location -googleMap"
)
.populate("postedBy", "name username email phone company")
.sort({ createdAt: -1 })
.limit(12);
res.json(ads);
} catch (err) {
console.log(err);
}
};
export const adsForRent = async (req, res) => {
try {
const ads = await Ad.find({ action: "Rent", published: true })
.select(
"-photos.Key -photos.key -photos.ETag -photos.Bucket -location -googleMap"
)
.populate("postedBy", "name username email phone company")
.sort({ createdAt: -1 })
.limit(12);
res.json(ads);
} catch (err) {
console.log(err);
}
};