Tell us what’s happening:
Hello!
So, I made the salon.sh script and all tasks passes but the following two:
- You can create a row in the
appointmentstable by running your script and entering1,555-555-5555,Fabio,10:30at each request for input if that phone number isn’t in thecustomerstable. The row should have thecustomer_idfor that customer, and theservice_idfor the service entered - You can create another row in the
appointmentstable by running your script and entering2,555-555-5555,11amat each request for input if that phone number is already in thecustomerstable. The row should have thecustomer_idfor that customer, and theservice_idfor the service entered
Running these steps manually works just fine.
If anyone could give some help.
Your code so far
#! /bin/bash
PSQL="psql -X --username=freecodecamp --dbname=salon --tuples-only -c"
echo -e "\n~~~~~ MY SALON ~~~~~\n"
echo -e "Welcome to My Salon, how can I help you?\n"
MAIN_MENU() {
if [[ $1 ]]
then
echo -e "\n$1"
fi
SERVICES_AVAILABLE=$($PSQL "SELECT service_id, name FROM services;")
echo "$SERVICES_AVAILABLE" | while read SERVICE_ID BAR SERVICE_NAME
do
echo "$SERVICE_ID) $SERVICE_NAME"
done
read SERVICE_ID_SELECTED
SERVICE_NAME_SELECTED=$($PSQL "SELECT name FROM services WHERE service_id = $SERVICE_ID_SELECTED;")
if [[ -z $SERVICE_NAME_SELECTED ]]
then
MAIN_MENU "I could not find that service. What would you like today?"
else
# get customer info
echo -e "\nWhat's your phone number?"
read CUSTOMER_PHONE
CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$CUSTOMER_PHONE';")
# if customer doesn't exist
if [[ -z $CUSTOMER_NAME ]]
then
# get new customer name
echo -e "\nI don't have a record for that phone number, what's your name?"
read CUSTOMER_NAME
# insert new customer
INSERT_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers (name, phone) VALUES ('$CUSTOMER_NAME', '$CUSTOMER_PHONE');")
fi
echo -e "\nWhat time would you like your $(echo $SERVICE_NAME_SELECTED | sed -E 's/^ *| *$//g'), $(echo $CUSTOMER_NAME | sed -E 's/^ *| *$//g')?"
read SERVICE_TIME
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE';")
INSERT_APPOINTMENT_RESULT=$($PSQL "INSERT INTO appointments (customer_id, service_id, time) VALUES ($CUSTOMER_ID, $SERVICE_ID_SELECTED, '$SERVICE_TIME');")
echo -e "\nI have put you down for a $(echo $SERVICE_NAME_SELECTED | sed -E 's/^ *| *$//g') at $(echo $SERVICE_TIME | sed -E 's/^ *| *$//g'), $(echo $CUSTOMER_NAME | sed -E 's/^ *| *$//g')."
fi
}
MAIN_MENU
