text: const express = require("express");
  const router = express.Router();
  const groceryItemsModel = require("../models/groceryItemsModel");
  
  router.post("/add", async function (request, response) {
    try {
      const additionResponse = await groceryItemsModel.create(request.body);
      console.log("additionResponse", additionResponse);
      response.send({ result: "item added successfully" });
    } catch (err) {
      console.log("error occured in adding item", err);
    }
  });
  router.get("/list", async function (request, response) {
    try {
      const groceryList = await groceryItemsModel.find({}, { __v: 0 });
      response.send({ result: groceryList });
    } catch (err) {
      console.log("error occured in adding item", err);
    }
  });
  
  // Update the items
  router.put("/update", async function (request, response) {
    try {
      // Step 1: Find the record
      const groceryItemRecord = await groceryItemsModel.findOne({
        _id: request.body._id,
      });
      // Step 2: Update the record/object
      groceryItemRecord.isPurchased = true;
      console.log("groceryItemRecord", groceryItemRecord);
      // Save the update back into database
      await groceryItemRecord.save();
      response.send({ result: "Item updated successfully" });
    } catch (err) {
      console.log("error occured in adding item", err);
    }
  });
  
  // delete request
  router.delete("/delete", async function (request, response) {
    try {
      // Use deleteOne method to delete the items
      await groceryItemsModel.deleteOne({ _id: request.body._id });
      response.send({ result: "Item deleted successfully" });
    } catch (e) {
      console.log("Error occured", err);
    }
  });
  module.exports = router;
  