server.js
// Add a role and connection query
Add a role and connection query
Add a role and connection query
function addRole() {
  connection.query("select name from department", function (err, res) {
    if (err) throw err;
    deptName = [];
    for (i = 0; i < res.length; i++) {
      deptName.push(res[i].name);
    }
    inquirer
      .prompt([
        {
          type: "input",
          name: "role",
          message: "Input the title of the new role"
        },
        {
          type: "input",
          name: "salary",
          message: "Input the salary of the new role"
        },
        {
          type: "list",
          name: "department",
          message: "Assign this role to a department",
          choices: deptName
        }
      ])
      .then(function ({ role, salary, department }) {
        connection.query(
          "select id from department where name = ?",
          [department],
          function (err, res) {
            if (err) throw err;
            let deptId = res[0].id;
            connection.query(
              "insert into employee_role(title, salary, department_id) values (?, ?, ?)",
              [role, salary, deptId],
              function (err, res) {
                if (err) throw err;
                console.table(res);
                start();
              }
            );
          }
        );
      });
  });
}
function addRole ( ) { connection . query ( "select name from department" , function ( err , res ) { if ( err ) throw err ; deptName = [ ] ; for ( i = 0 ; i < res . length ; i ++ ) { deptName . push ( res [ i ] . name ) ; } inquirer . prompt ( [ { type : "input" , name : "role" , message : "Input the title of the new role" } , { type : "input" , name : "salary" , message : "Input the salary of the new role" } , { type : "list" , name : "department" , message : "Assign this role to a department" , choices : deptName } ] ) . then ( function ( { role , salary , department } ) { connection . query ( "select id from department where name = ?" , [ department ] , function ( err , res ) { if ( err ) throw err ; let deptId = res [ 0 ] . id ; connection . query ( "insert into employee_role(title, salary, department_id) values (?, ?, ?)" , [ role , salary , deptId ] , function ( err , res ) { if ( err ) throw err ; console . table ( res ) ; start ( ) ; } ) ; } ) ; } ) ; } ) ; }
Add a role and connection query
Add a role and connection query