text: const express = require('express');
  const router = express.Router();
  const db = require('../../db/connection');
  const inputCheck = require('../../utils/inputCheck');
  
  router.get('/employee', (req, res) => {
      const sql = `SELECT * FROM employee ORDER BY last_name`;
    
      db.query(sql, (err, rows) => {
        if (err) {
          res.sendStatus(500).json({ error: err.message });
          return;
        }
        res.json({
          message: 'success',
          data: rows,
        });
      });
    });
  
    // Get single employee
  router.get('/employee/:id', (req, res) => {
      const sql = `SELECT * FROM employee WHERE id = ?`;
      const params = [req.params.id];
    
      db.query(sql, params, (err, row) => {
        if (err) {
          res.sendStatus(400).json({ error: err.message });
          return;
        }
        res.json({
          message: 'success',
          data: row
        });
      });
    });
  
    // Insert Employee
    router.post('/employee', ({ body }, res) => {
      // Data validation
      const errors = inputCheck(body, 'first_name', 'last_name', 'role_id', 'manager_id');
      if (errors) {
          res.sendStatus(400).json({ error: errors });
      return;
      }
      const sql = `INSERT INTO employee (first_name, last_name, role_id, manager_id) VALUES (?,?,?,?)`;
      const params = [body.first_name, body.last_name, body.role_id, body.manager_id];
    
      db.query(sql, params, (err, result) => {
        if (err) {
          res.sendStatus(400).json({ error: err.message });
          return;
        }
        res.json({
          message: 'success',
          data: body
        });
      });
    });
  
    // Update Employee
    router.put('/employee/:id', (req, res) => {
      
    
      const sql = `UPDATE employee SET (first_name, last_name, role_id, manager_id) VALUES (?,?,?,?) WHERE id = ?`;
      const params = [req.body.email, req.params.id];
    
      db.query(sql, params, (err, result) => {
        if (err) {
          res.status(400).json({ error: err.message });
        } else if (!result.affectedRows) {
          res.json({
            message: 'Voter not found'
          });
        } else {
          res.json({
            message: 'success',
            data: req.body,
            changes: result.affectedRows
          });
        }
      });
    });
  
    // Delete Employee
    router.delete('/employee/:id', (req, res) => {
      const sql = `DELETE FROM employee WHERE id = ?`;
    
      db.query(sql, req.params.id, (err, result) => {
        if (err) {
          res.sendStatus(400).json({ error: res.message });
        } else if (!result.affectedRows) {
          res.json({
            message: 'Employee not found'
          });
        } else {
          res.json({
            message: 'deleted',
            changes: result.affectedRows,
            id: req.params.id
          });
        }
      });
    });
  
    module.exports = router;