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


router.post('/deleteOD',(req,res)=>{
  console.log("delete api");
  
    const id = req.body.id;
    
    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 = `DELETE from finehhdi_CIL.SetOperationDescription where id = ${id}`;
      console.log(query);
      connection.query(query,(err,data)=>{
        connection.release();
          if (err) {
              console.log("error ==>", err);
         
          if(err.code==='ENOTFOUND'){
              res.status(404).json({
                message:"Internet Connection Failed",
                results: 'failed'
              })
              
            }
            else{
              console.log(err);
              res.status(401).json({
                message: "Request failed",
                results: "Failed",
              });
              
            }
          } 
          else {
            
              res.status(200).json({
                message: "Deleted Successfully",
                results: "Success",
              });
            
          }
      })
  })

})
module.exports=router;