var express=require('express')
const router = express.Router();
const db = require("../../utils/database");
const dbFuntion=require("../../utils/dbfunction")
const { response } = require('express');


router.post("/createLines", (req, res) => {
const name=req.body.lineName


var query=`insert into finehhdi_eDefect.lineNames (lineName) values ('${name}');`
db.query(query,(err,result)=>{
   if(err){
       console.log(err);
    res.status(401).json({
        message:"Line creation failed",
        results:"Failed"
    })

   }
   else{
    res.status(201).json({
        message:"Line Created Successfully",
        results:"Success" 

    })

   }

})

})

router.get("/getLines", (req, res) => {
    var query = `select * from finehhdi_eDefect.lineNames order by id desc`

    db.query(query, (err, result) => {
        if (err) {
            console.log(err);
            res.status(401).json({
                message: "Some error in Line selection",
                results: "Failed",
                line: []
            })

        }
        else {
            res.status(201).json({
                message: "type Successfully",
                results: "Success",
                line: result

            })

        }

    })

})


module.exports = router;