function viewEmployeesByDepartment() {
  db.findAllDepartments().then(([rows]) => {
    let departments = rows;
    const departmentChoices = departments.map(({ id, name }) => ({
      name: name,
      value: id,
    }));

    prompt([
      {
        type: "list",
        name: "departmentId",
        message: "Which department would you like to see employees for?",
        choices: departmentChoices,
      },
    ])
      .then((res) => db.findAllEmployeesByDepartment(res.departmentId))
      .then(([rows]) => {
        let employees = rows;
        console.log("\n");
        console.table(employees);
      })
      .then(() => loadMainPrompts());
  });
}
// View all employees that belong to a department
View all employees that belong to a department
View all employees that belong to a department
function viewEmployeesByDepartment() {
  db.findAllDepartments().then(([rows]) => {
    let departments = rows;
    const departmentChoices = departments.map(({ id, name }) => ({
      name: name,
      value: id,
    }));
    prompt([
      {
        type: "list",
        name: "departmentId",
        message: "Which department would you like to see employees for?",
        choices: departmentChoices,
      },
    ])
      .then((res) => db.findAllEmployeesByDepartment(res.departmentId))
      .then(([rows]) => {
        let employees = rows;
        console.log("\n");
        console.table(employees);
      })
      .then(() => loadMainPrompts());
  });
}
function viewEmployeesByDepartment ( ) { db . findAllDepartments ( ) . then ( ( [ rows ] ) => { let departments = rows ; const departmentChoices = departments . map ( ( { id , name } ) => ( { name : name , value : id , } ) ) ; prompt ( [ { type : "list" , name : "departmentId" , message : "Which department would you like to see employees for?" , choices : departmentChoices , } , ] ) . then ( ( res ) => db . findAllEmployeesByDepartment ( res . departmentId ) ) . then ( ( [ rows ] ) => { let employees = rows ; console . log ( "\n" ) ; console . table ( employees ) ; } ) . then ( ( ) => loadMainPrompts ( ) ) ; } ) ; }
View all employees that belong to a department
View all employees that belong to a department