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

// Select All Complains
router.get("/SelectComplains", (req, res) => {

    let query = `SELECT * FROM finehhdi_fineAD.complain`

    console.log(query);

    db.query(query, (err, data) => {
        if (err) {
            res.status(500).send({ msg: "Error while Successfully" })
        }
        else {
            res.status(200).send(
                {
                    msg: "Select Successfully",
                    data: data
                }
            )
        }
    })

})


//  Select Individual's Data from email
router.post('/SelectIndiComplain/:userEmail',(req,res)=>{
    const email = req.params.userEmail;
    const userAssigned = req.body.useremail;
    console.log(email);
    let query=`SELECT * FROM finehhdi_fineAD.complain where userEmail= "${email}" OR userAssigned="${email}"`
    console.log(query);
    db.query(query,(err,data)=>{
        if(err){
            res.status(500).send({msg:"Error While Selection"})
        }
        else{
            res.status(200).send(
                {
                    msg:"Seleted Successfully",
                    data:data
                }
            )
        }
    })

})


//select all ofs complain
router.get("/SelectOfsComplain", (req, res) => {

    let query = `SELECT * FROM finehhdi_fineAD.complain where forOfs=1`

    console.log(query);

    db.query(query, (err, data) => {
        if (err) {
            res.status(500).send({ msg: "Error while Successfully" })
        }
        else {
            res.status(200).send(
                {
                    msg: "Select Successfully",
                    data: data
                }
            )
        }
    })

})

// select all bos complain
router.get("/SelectBosComplain", (req, res) => {

    let query = `SELECT * FROM finehhdi_fineAD.complain where forBos=1`

    console.log(query);

    db.query(query, (err, data) => {
        if (err) {
            res.status(500).send({ msg: "Error while Successfully" })
        }
        else {
            res.status(200).send(
                {
                    msg: "Select Successfully",
                    data: data
                }
            )
        }
    })

})


// select all DH complain 
router.get("/SelectDHComplain", (req, res) => {

    let query = `SELECT * FROM finehhdi_fineAD.complain where forDH=1`

    console.log(query);

    db.query(query, (err, data) => {
        if (err) {
            res.status(500).send({ msg: "Error while Successfully" })
        }
        else {
            res.status(200).send(
                {
                    msg: "Select Successfully",
                    data: data
                }
            )
        }
    })

})



module.exports = router;