// routes/ad
router.get("/user-ads", requireSignin, ad.userAds);

// controllers
export const userAds = async (req, res) => {
  try {
    const perPage = 2; // change as required
    const page = req.params.page ? req.params.page : 1;

    const total = await Ad.find({
      postedBy: req.user._id,
    });

    const ads = await Ad.find({ postedBy: req.user._id })
      .select(
        "-photos.Key -photos.key -photos.ETag -photos.Bucket -location -googleMap"
      )
      .populate("postedBy", "name username email phone company")
      .skip((page - 1) * perPage)
      .sort({ createdAt: -1 })
      .limit(perPage);
    res.json({ ads, total: total?.length });
  } catch (err) {
    console.log(err);
  }
};