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

router.post("/createConfig", (req, res) => {
  const area = req.body.area;
  const subassembly = req.body.subassembly;
  const machineName = req.body.machineName;
  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 = `INSERT into finehhdi_CIL.CILConfig (area, subassembly, machineName) values ("${area}","${subassembly}","${machineName}")`
    console.log("Create Config Query", query);
  
    connection.query(query, (err, data) => {
      connection.release();
      if (err) {
        console.log("Error ", err);
      } else {
        res.status(200).json({
          message: "Successfully Created",
          results: "Success",
        });
      }
    });
  })

});
module.exports = router;
