var express = require("express");
const router = express.Router();
const db = require("../../utils/database");
const moment = require("moment");

router.post("/issueResolved", (req, res) => {
  const id = req.body.id;
  const closerDate = moment().format("DD/MM/YYYY");

  let query = `UPDATE finehhdi_fineAD.complain SET isResolved = 1 , closerDate ="${closerDate}"where id = ${id}`;

  db.query(query, (err, data) => {
    if (err) {
      res.status(500).send({ msg: "Failed to Update" });
    } else {
      res.status(200).send({ msg: "Updated Successfully" });
      console.log("closer", closerDate);
    }
  });
});

//configure complain

router.post("/configureComplain", (req, res) => {
  const id = req.body.id;
  const userAssigned = req.body.userAssigned;
  const expectedCloserDate = req.body.expectedCloserDate;
  const userNameAssigned = req.body. userNameAssigned;

  let query = `UPDATE finehhdi_fineAD.complain SET userAssigned="${userAssigned}", expectedCloserDate="${expectedCloserDate}" , userNameAssigned="${ userNameAssigned}" where id = ${id}`;
  console.log(query);

  db.query(query, (err, data) => {
    if (err) {
      console.log(err);
      res.status(500).send({ msg: "Failed to Update" });
    } else {
      res.status(200).send({ msg: "Updated Successfully" });
    }
  });
});

module.exports = router;
