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

router.post("/deleteMachine", (req, res) => {
  const id = req.body.id;
  db.getConnection((err, connection) => {
    if (err) {
      console.log("database not connected error: >>>", err);
      throw err;
    }
    console.log("get Connection");
    let dQuer = `delete from finehhdi_eDefect.machineTypes where id=${id}`;
    connection.query(dQuer, (err, data) => {
      connection.release();
      if (err) {
        res.status(401).json({
          message: "error! Department cant be deleted for somereason",
          results: "Failed",
        });
      } else {
        res.status(200).json({
          message: "Department Deleted Successfully",
          results: "Success",
        });
      }
    });
    console.log("release Connection");
  });
});

module.exports = router;
