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

router.post("/updateMachine", (req, res) => {
  const id = req.body.id;
  const machineTypes = req.body.machineTypes;
  var department = req.body.department;
  var equipmentName = req.body.equipmentName;

  db.getConnection((err, connection) => {
    if (err) {
      console.log("database not connected error: >>>", err);
      throw err;
    }
    console.log("get Connection");
    let uQuer = `update finehhdi_eDefect.machineTypes set 
      machineTypes='${machineTypes}',
      department='${department}',
      equipmentName='${equipmentName}'
      where id=${id}`;
    connection.query(uQuer, (err, data) => {
      connection.release();
      if (err) {
        res.status(401).json({
          message: "error! machineTypes cant be Updated for somereason",
          results: "Failed",
        });
      } else {
        res.status(200).json({
          message: "machineTypes Updated Successfully",
          results: "Success",
        });
      }
    });
    console.log("release Connection");
  });
});

module.exports = router;
