function addEmployee() {
    connection.query('SELECT * FROM role', function (err, res) {
        if (err) throw err;
        inquirer
            .prompt([
                {
                    name: 'first_name',
                    type: 'input', 
                    message: "What is the employee's fist name? ",
                },
                {
                    name: 'last_name',
                    type: 'input', 
                    message: "What is the employee's last name? "
                },
                {
                    name: "choice",
                    type: "rawlist",
                    message: "Whats their managers name?",
                    choices: selectManager()
                },
                {
                    name: 'role', 
                    type: 'list',
                    choices: function() {
                    var roleArray = [];
                    for (let i = 0; i < res.length; i++) {
                        roleArray.push(res[i].title);
                    }
                    return roleArray;
                    },
                    message: "What is this employee's role? "
                }
                ]).then(function (answer) {
                    var role_id;
                    var managerId = selectManager().indexOf(answer.choice) + 1
                    for (let a = 0; a < res.length; a++) {
                        if (res[a].title == answer.role) {
                            role_id = res[a].id;
                            console.log(role_id)
                        }                  
                    }  
                    connection.query(
                    'INSERT INTO employee SET ?',
                    {
                        first_name: answer.first_name,
                        last_name: answer.last_name,
                        manager_id: managerId,
                        role_id: role_id,
                    },
                    function (err) {
                        if (err) throw err;
                        console.log('Your employee has been added!');
                        questions();
                    })
                })
        })
    managersArr = [];
}
// add an employee to the database

add an employee to the database
add an employee to the database
function addEmployee() {
    connection.query('SELECT * FROM role', function (err, res) {
        if (err) throw err;
        inquirer
            .prompt([
                {
                    name: 'first_name',
                    type: 'input', 
                    message: "What is the employee's fist name? ",
                },
                {
                    name: 'last_name',
                    type: 'input', 
                    message: "What is the employee's last name? "
                },
                {
                    name: "choice",
                    type: "rawlist",
                    message: "Whats their managers name?",
                    choices: selectManager()
                },
                {
                    name: 'role', 
                    type: 'list',
                    choices: function() {
                    var roleArray = [];
                    for (let i = 0; i < res.length; i++) {
                        roleArray.push(res[i].title);
                    }
                    return roleArray;
                    },
                    message: "What is this employee's role? "
                }
                ]).then(function (answer) {
                    var role_id;
                    var managerId = selectManager().indexOf(answer.choice) + 1
                    for (let a = 0; a < res.length; a++) {
                        if (res[a].title == answer.role) {
                            role_id = res[a].id;
                            console.log(role_id)
                        }                  
                    }  
                    connection.query(
                    'INSERT INTO employee SET ?',
                    {
                        first_name: answer.first_name,
                        last_name: answer.last_name,
                        manager_id: managerId,
                        role_id: role_id,
                    },
                    function (err) {
                        if (err) throw err;
                        console.log('Your employee has been added!');
                        questions();
                    })
                })
        })
    managersArr = [];
}
function addEmployee ( ) { connection . query ( 'SELECT * FROM role' , function ( err , res ) { if ( err ) throw err ; inquirer . prompt ( [ { name : 'first_name' , type : 'input' , message : "What is the employee's fist name? " , } , { name : 'last_name' , type : 'input' , message : "What is the employee's last name? " } , { name : "choice" , type : "rawlist" , message : "Whats their managers name?" , choices : selectManager ( ) } , { name : 'role' , type : 'list' , choices : function ( ) { var roleArray = [ ] ; for ( let i = 0 ; i < res . length ; i ++ ) { roleArray . push ( res [ i ] . title ) ; } return roleArray ; } , message : "What is this employee's role? " } ] ) . then ( function ( answer ) { var role_id ; var managerId = selectManager ( ) . indexOf ( answer . choice ) + 1 for ( let a = 0 ; a < res . length ; a ++ ) { if ( res [ a ] . title == answer . role ) { role_id = res [ a ] . id ; console . log ( role_id ) } } connection . query ( 'INSERT INTO employee SET ?' , { first_name : answer . first_name , last_name : answer . last_name , manager_id : managerId , role_id : role_id , } , function ( err ) { if ( err ) throw err ; console . log ( 'Your employee has been added!' ) ; questions ( ) ; } ) } ) } ) managersArr = [ ] ; }
add an employee to the database
add an employee to the database