function addEmployee() {
    db.query(
        `SELECT CONCAT(employee.first_name, " ",employee.last_name) AS full_name FROM employee`,
        function (err, results) {
            if(err) throw err;
            let managerList = results.map(manager => ({
                name: manager.full_name, value: manager.id
            }));

            db.query(
                `SELECT * FROM role`,
                function (err, results) {
                    if (err) throw err;

                    let roleList = results.map(role => ({
                        name: role.title, value: role.id
                    }));

                    inquirer.prompt([
                        {
                            type: "input",
                            name: "empFistName",
                            message: "Please enter Empolyee's first name here:"
                        },
                        {
                            type: "input",
                            name: "empLastName",
                            message: "Please enter the Employee's last name here:"
                        },
                        {
                            type: "list",
                            name: "empRole",
                            message: "Please select the employee's new role.",
                            choices: roleList
                        },
                        {
                            type: "list",
                            name: "empManager",
                            message: "Please select the new Employee's Manager Name.",
                            choices: managerList
                        }
                    ])
                        .then(answers => {
                            db.query(
                                `INSERT INTO employee SET ?`,
                                {
                                    first_name: answers.empFistName,
                                    last_name: answers.empLastName,
                                    role_id: answers.empRole,
                                    manager_id: answers.empManager
                                },
                                function (err, results) {
                                    if (err) throw err;
                                    console.log('\x1b[33m%s\x1b[0m', 'New Employee Added Successfully!\n');
                                    comfirmPrompt();
                                }
                            );
                        })
                }
            );
        }
    );
}
//function to add new employee to the database
function to add new employee to the database
function to add new employee to the database
function addEmployee() {
    db.query(
        `SELECT CONCAT(employee.first_name, " ",employee.last_name) AS full_name FROM employee`,
        function (err, results) {
            if(err) throw err;
            let managerList = results.map(manager => ({
                name: manager.full_name, value: manager.id
            }));
            db.query(
                `SELECT * FROM role`,
                function (err, results) {
                    if (err) throw err;
                    let roleList = results.map(role => ({
                        name: role.title, value: role.id
                    }));
                    inquirer.prompt([
                        {
                            type: "input",
                            name: "empFistName",
                            message: "Please enter Empolyee's first name here:"
                        },
                        {
                            type: "input",
                            name: "empLastName",
                            message: "Please enter the Employee's last name here:"
                        },
                        {
                            type: "list",
                            name: "empRole",
                            message: "Please select the employee's new role.",
                            choices: roleList
                        },
                        {
                            type: "list",
                            name: "empManager",
                            message: "Please select the new Employee's Manager Name.",
                            choices: managerList
                        }
                    ])
                        .then(answers => {
                            db.query(
                                `INSERT INTO employee SET ?`,
                                {
                                    first_name: answers.empFistName,
                                    last_name: answers.empLastName,
                                    role_id: answers.empRole,
                                    manager_id: answers.empManager
                                },
                                function (err, results) {
                                    if (err) throw err;
                                    console.log('\x1b[33m%s\x1b[0m', 'New Employee Added Successfully!\n');
                                    comfirmPrompt();
                                }
                            );
                        })
                }
            );
        }
    );
}
function addEmployee ( ) { db . query ( ` ` , function ( err , results ) { if ( err ) throw err ; let managerList = results . map ( manager => ( { name : manager . full_name , value : manager . id } ) ) ; db . query ( ` ` , function ( err , results ) { if ( err ) throw err ; let roleList = results . map ( role => ( { name : role . title , value : role . id } ) ) ; inquirer . prompt ( [ { type : "input" , name : "empFistName" , message : "Please enter Empolyee's first name here:" } , { type : "input" , name : "empLastName" , message : "Please enter the Employee's last name here:" } , { type : "list" , name : "empRole" , message : "Please select the employee's new role." , choices : roleList } , { type : "list" , name : "empManager" , message : "Please select the new Employee's Manager Name." , choices : managerList } ] ) . then ( answers => { db . query ( ` ` , { first_name : answers . empFistName , last_name : answers . empLastName , role_id : answers . empRole , manager_id : answers . empManager } , function ( err , results ) { if ( err ) throw err ; console . log ( '\x1b[33m%s\x1b[0m' , 'New Employee Added Successfully!\n' ) ; comfirmPrompt ( ) ; } ) ; } ) } ) ; } ) ; }
function to add new employee to the database
function to add new employee to the database