import { FoodItem, IFoodItem } from "../model/foodItem";

export class ProductController {
  async handleGetProduct(req, res) {
    const query = req.query.title;
    let limit = 10;

    if (req.query.limit) {
      limit = req.query.limit;
    }

    await FoodItem.find(
      { title: { $regex: `${query}`, $options: "i" } },
      (err, result: IFoodItem[]) => {
        res.json(result);
      }
    ).limit(limit);
  }
}

export const productController = new ProductController();
