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

router.post("/updateConfig", (req, res) => {
  const id = req.body.id;
  const area = req.body.area;
  const subassembly = req.body.subassembly;
  const machineName = req.body.machineName;

  console.log("req.body ========>", req.body);
  db.getConnection((err, connection) => {
    if (err) {
      console.log("database not connected error: >>>", err);
      res.send(500).status({
        msg: "Error from database",
        err: err,
      });
    }
    let query = `update finehhdi_CIL.CILConfig set area="${area}",subassembly="${subassembly}" ,machineName="${machineName}" where id=${id}`;
    console.log("update query", query);
  
    connection.query(query, (err, data) => {
      connection.release();
      if (err) {
        console.log("error found", err);
      } else {
        res.status(200).json({
          message: "Successfully Updated",
          results: "success",
        });
      }
    });
  })

});
module.exports = router;
