Tell us what’s happening:
The test “If you pick a service that doesn’t exist, you should be shown the same list of services again” is not passing. How to fix? All other tests passed.
Your code so far
#! /bin/bash
echo -e "\n~~ Dong's Salon ~~"
# PSQL="psql --username=freecodecamp --dbname=salon -c"
PSQL="psql --username=freecodecamp --dbname=salon -t --no-align -c"
# PSQL="psql --username=freecodecamp --dbname=salon -t --no-align -F"," -c"
ALL_SERVICES=$($PSQL "SELECT service_id, name FROM services ORDER BY service_id")
DISPLAY_SERVICES () {
if [[ $1 ]]
then
echo -e "\n$1"
fi
if [[ $2 ]]
then
echo "$2" | while IFS="|" read SERVICE_ID SERVICE_NAME
do
echo "$SERVICE_ID) $SERVICE_NAME"
done
fi
}
APPOINTMENT_MENU () {
if [[ $1 ]]
then
echo -e "\n$1"
fi
read SERVICE_ID_SELECTED
# check if input is valid
if [[ ! $SERVICE_ID_SELECTED =~ ^[0-9]+$ ]]
then
APPOINTMENT_MENU "Enter a valid number\n"
return
fi
# check if any service with that number
CHOSEN_SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE service_id = $SERVICE_ID_SELECTED")
if [[ -z $CHOSEN_SERVICE_NAME ]]
then
DISPLAY_SERVICES "I could not find that service. What would you like today?" "$ALL_SERVICES"
APPOINTMENT_MENU
return
fi
# Get customers details
echo -e "\nEnter your phone number:"
read CUSTOMER_PHONE
CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$CUSTOMER_PHONE'")
# if customer not found
if [[ -z $CUSTOMER_NAME ]]
then
echo -e "\nThere is no record for that phone number, what's your name?"
read CUSTOMER_NAME
INSERT_RESULT=$($PSQL "INSERT INTO customers(phone, name) VALUES('$CUSTOMER_PHONE', '$CUSTOMER_NAME')")
fi
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE'")
echo -e "\nWhat time would you like your appointment $CUSTOMER_NAME?"
read SERVICE_TIME
# if [[ ! $SERVICE_TIME =~ ^[0-9][0-9]:[0-9][0-9]$ ]]
# then
# APPOINTMENT_MENU "Enter a valid time\n"
# fi
APPOINTMENT_RESULT=$($PSQL "INSERT INTO appointments(customer_id, service_id, time) VALUES($CUSTOMER_ID, $SERVICE_ID_SELECTED, '$SERVICE_TIME')")
if [[ -z $APPOINTMENT_RESULT ]]
then
APPOINTMENT_MENU "Time not possible"
fi
echo -e "\nI have put you down for a $CHOSEN_SERVICE_NAME at $SERVICE_TIME, $CUSTOMER_NAME."
}
CANCEL_APPOINTMENT() {
:
}
EXIT() {
echo -e "\nTill next time\n"
}
DISPLAY_SERVICES "Welcome to Dong's Salon, how can I help you?\n" "$ALL_SERVICES"
APPOINTMENT_MENU
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36
Challenge Information:
Build a Salon Appointment Scheduler - Build a Salon Appointment Scheduler


