I can’t pass this one test
“If you pick a service that doesn’t exist, you should be shown the same list of services again”
My script prints list of new services correctly if wrong number is selected.
I tried to make my list of services smaller, doesn’t work.
Adjusted the output to match the examples.txt.
Services name have to be the same as examples.txt to pass this test?
It works but can’t pass this test. What i need to do to pass this checkmark?(all the other ones are passed, but this one)
#!/bin/bash
PSQL="psql --username=freecodecamp --dbname=salon --tuples-only -c"
echo -e "\n~~~~~ Best Cut ~~~~~\n"
echo -e "Welcome to Best Cut, how can i help you?\n"
PRINT_SERVICE_LIST(){
#print list of services from service table, while loop should work
SERVICES_LIST=$($PSQL "SELECT service_id, name FROM services")
echo "$SERVICES_LIST" | grep -E '^[[:space:]]*[0-9]+.*$' | sed -e 's/^[[:space:]]*//;s/ |/)/' | while read SERVICE_ID SERVICE_NAME
do
echo -e "$SERVICE_ID $SERVICE_NAME"
done
}
SERVICE_LIST(){
#print first parameter passed to function
if [[ $1 ]]; then #might dont need that
echo -e "\n$1"
fi
PRINT_SERVICE_LIST
#get user service
read SERVICE_ID_SELECTED
# if input is not a number
if [[ ! $SERVICE_ID_SELECTED =~ ^[0-9]+$ ]]; then
echo "This is not valid service number"
else
# check service availibility
CHECK_SERVICE=$($PSQL "SELECT service_id FROM services WHERE service_id=$SERVICE_ID_SELECTED")
echo $CHECK_SERVICE
if [[ -z $CHECK_SERVICE ]]; then
echo "I could not find that service. What would you like today?"
SERVICE_LIST
else
echo -e "\nWhat's your phone number?"
read CUSTOMER_PHONE
CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone='$CUSTOMER_PHONE'")
if [[ -z $CUSTOMER_NAME ]]; then
echo -e "\nI don't have a record for that phone number, what's your name?"
read CUSTOMER_NAME
INSERT_CUSTOMER_DATA=$($PSQL "INSERT INTO customers(phone, name) VALUES('$CUSTOMER_PHONE', '$CUSTOMER_NAME')")
fi
echo -e "\nWhat time would you like your cut, $CUSTOMER_NAME?"
read SERVICE_TIME
GET_CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone='$CUSTOMER_PHONE'")
INSERT_CUSTOMER_APPOINTMENT=$($PSQL "INSERT INTO appointments(time, customer_id, service_id) VALUES('$SERVICE_TIME', $GET_CUSTOMER_ID, $SERVICE_ID_SELECTED)")
GET_CUSTOMER_SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE service_id=$SERVICE_ID_SELECTED")
echo -e "\nI have put you down for a $GET_CUSTOMER_SERVICE_NAME at $SERVICE_TIME, $CUSTOMER_NAME.\n"
fi
fi
}
SERVICE_LIST