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 even though it is working as expected when running manually.
I’ve been stuck on this for quite some time now. Any input would be much appreciated.
Thank You!
Your code so far
#!/bin/bash
PSQL="psql --username=freecodecamp --dbname=salon --no-align --tuples-only -c"
echo -e "\n~~~~~ MY SALON ~~~~~"
echo -e "\nWelcome, how can I help you today?"
MAIN_MENU() {
if [[ $1 ]]
then
echo $1
fi
$PSQL "SELECT service_id, name FROM services ORDER BY service_id" | while IFS="|" read SERVICE_ID SERVICE_NAME
do
echo "$SERVICE_ID) $SERVICE_NAME"
done
SERVICE_COUNT=$($PSQL "SELECT COUNT(*) FROM services WHERE service_id IS NOT NULL")
read SERVICE_ID_SELECTED
if [[ ! $SERVICE_ID_SELECTED =~ ^[1-$SERVICE_COUNT]$ ]]
then
MAIN_MENU "I could not find that service. What would you like today?"
else
SERVICE=$($PSQL "SELECT name FROM services WHERE service_id = $SERVICE_ID_SELECTED")
echo -e "\nWhat's your phone number?"
read CUSTOMER_PHONE
fi
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE'")
if [[ -z $CUSTOMER_ID ]]
then
echo -e "\nI don't have a record for that phone number, what's your name?"
read CUSTOMER_NAME
CUSTOMER_RESULT=$($PSQL "INSERT INTO customers (name, phone) VALUES('$CUSTOMER_NAME', '$CUSTOMER_PHONE')")
fi
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE'")
CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone = '$CUSTOMER_PHONE'")
if [[ $CUSTOMER_ID ]]
then
echo -e "\nWhat time would you like your service, $CUSTOMER_NAME?"
read SERVICE_TIME
APPOINTMENT_RESULT=$($PSQL "INSERT INTO appointments (service_id, customer_id, time) VALUES ($SERVICE_ID_SELECTED, $CUSTOMER_ID, '$SERVICE_TIME')")
fi
echo -e "I have put you down for a $SERVICE at $SERVICE_TIME, $CUSTOMER_NAME."
}
MAIN_MENU
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Salon Appointment Scheduler - Build a Salon Appointment Scheduler
