<commit_before>const command = process.argv[2]
const arg = process.argv.slice([3]).join().replace(/\,/g, ' ')
const { queryFunctions, pgp } = require('./db/db.js')
require('console.table');

const processCommands = () => {
  switch (command) {
    case 'guests':
      return queryFunctions.list()
        .then( (value) => {
          let outerArr = []
          for(let i = 0; i < value.length; i++) {
            let arr = []
            arr.push('|  ' + value[i].id, value[i].name, value[i].email)
            outerArr.push(arr)
          }
          pgp.end()
          console.table(['ID','Name','Email'], outerArr)
        })

    case 'rooms':
    if(arg) {
      return queryFunctions.listAvailable()
        .then( (value) => {
          let outerArr = [];
          for (let i = 0; i < value.length; i++) {
            let arr = []
            arr.push('|  ' + value[i].room_number, value[i].capacity, value[i].available)
            outerArr.push(arr)
          }
          pgp.end()
          console.table(['Room Number', 'Capacity', 'Available'], outerArr)
        })
    } else {
      return queryFunctions.listAll()
        .then((value) => {
          let outerArr = [];
          for (let i = 0; i < value.length; i++) {
            let arr = []
            arr.push('|  ' + value[i].room_number, value[i].capacity, value[i].available)
            outerArr.push(arr)
          }
          pgp.end()
          console.table(['Room Number', 'Capacity', 'Available'], outerArr)

        })   
       }

    case 'bookings':
       if(arg) {
         return queryFunctions.single(arg)
          .then((value) => {
            let outerArr = [];
            for (let i = 0; i < value.length; i++) {
              let arr = []
              arr.push('|  ' + value[i].room_number, value[i].name, value[i].check_in, value[i].check_out)
              outerArr.push(arr)
            }
            pgp.end()
            console.table(['Room Number', 'Guest Name', 'Check-In', 'Check-Out'], outerArr)
          })
       }else{
         return queryFunctions.bookings()
           .then((value) => {
             let outerArr = [];
             for (let i = 0; i < value.length; i++) {
               let arr = []
               arr.push('|  ' + value[i].room_number, value[i].name, value[i].check_in, value[i].check_out)
               outerArr.push(arr)
             }
             pgp.end()
             console.table(['Room Number', 'Guest Name', 'Check-In', 'Check-Out'], outerArr)
           })
       }
  }
}

  processCommands(command)
<commit_msg>add error handlers to hotel.js<commit_after>const command = process.argv[2]
let arg = process.argv.slice([3]).join().replace(/\,/g, ' ')
const { queryFunctions, pgp } = require('./db/db.js')
require('console.table');

const processCommands = () => {

  console.log(command)
  if(!command) {
    throw 'Must Enter Command'
  }

  switch (command) {
    case 'guests':
      return queryFunctions.list()
        .then( (value) => {
          let outerArr = []
          for(let i = 0; i < value.length; i++) {
            let arr = []
            arr.push( value[i].id, value[i].name, value[i].email)
            outerArr.push(arr)
          }
          pgp.end()
          console.table(['ID','Name','Email'], outerArr)
        })

    case 'rooms':
    if(arg) {
      console.log()
      return queryFunctions.listAvailable()
        .then( (value) => {
          let outerArr = [];
          for (let i = 0; i < value.length; i++) {
            let arr = []
            arr.push(value[i].room_number, value[i].capacity, value[i].available)
            outerArr.push(arr)
          }
          pgp.end()
          console.table(['Room Number', 'Capacity', 'Available'], outerArr)
        })
    } else {
      return queryFunctions.listAll()
        .then((value) => {
          let outerArr = [];
          for (let i = 0; i < value.length; i++) {
            let arr = []
            arr.push(value[i].room_number, value[i].capacity, value[i].available)
            outerArr.push(arr)
          }
          pgp.end()
          console.table(['Room Number', 'Capacity', 'Available'], outerArr)

        })   
       }

    case 'bookings':
       if(arg) {
         arg = arg.toUpperCase()
         return queryFunctions.single(arg)
          .then((value) => {
            let outerArr = [];
            for (let i = 0; i < value.length; i++) {
              let arr = []
              arr.push(value[i].room_number, value[i].name, value[i].check_in, value[i].check_out)
              outerArr.push(arr)
            }
            pgp.end()
            console.table(['Room Number', 'Guest Name', 'Check-In', 'Check-Out'], outerArr)
          })
       }else{
         return queryFunctions.bookings()
           .then((value) => {
             let outerArr = [];
             for (let i = 0; i < value.length; i++) {
               let arr = []
               arr.push(value[i].room_number, value[i].name, value[i].check_in, value[i].check_out)
               outerArr.push(arr)
             }
             pgp.end()
             console.table(['Room Number', 'Guest Name', 'Check-In', 'Check-Out'], outerArr)
           })
       }

       default:
         throw 'Command must be one of the following: guests, rooms, bookings'
  }
}

  processCommands(command)

{'fraction_non_alphanumeric': 0.16435272045028143, 'fraction_numerical': 0.002626641651031895, 'mean_word_length': 1.6628371628371628, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2172990', 'n_tokens_mistral': 1622, 'n_tokens_neox': 1599, 'n_words': 331}