Tell us what’s happening:
The test keep failing in the sub-task 19 and 20 . I double check everything but i can’t find the mistake. Please if somebody would help me would appreciate it a lot. Thank you
Your code so far
#!/bin/bash
PSQL="psql --username=freecodecamp --dbname=salon -t --no-align -c"
# Presentación
echo -e "\n~~~~~ MY SALON ~~~~~\n"
echo "Welcome to My Salon, how can I help you?"
# MAIN_MENU
MAIN_MENU() {
if [[ $1 ]]; then
echo -e "\n$1"
fi
# Mostrar los servicios disponibles
SERVICES_OFFERED=$($PSQL "SELECT service_id, name FROM services ORDER BY service_id")
if [[ -z $SERVICES_OFFERED ]]; then
echo -e "\nNo services available."
exit 1
fi
echo "$SERVICES_OFFERED" | while IFS="|" read SERVICE_ID SERVICE_NAME; do
echo "$SERVICE_ID) $SERVICE_NAME"
done
read SERVICE_ID_SELECTED
# Verificar si es un número válido
if [[ ! $SERVICE_ID_SELECTED =~ ^[0-9]+$ ]]; then
MAIN_MENU "I could not find that service. What would you like today?"
return
fi
# Verificar si el servicio existe
SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE service_id = $SERVICE_ID_SELECTED")
if [[ -z $SERVICE_NAME ]]; then
MAIN_MENU "I could not find that service. What would you like today?"
return
fi
# Pedir el número de teléfono una sola vez
echo -e "\nWhat's your phone number?"
read CUSTOMER_PHONE
# Buscar si el cliente ya existe
CUSTOMER_INFO=$($PSQL "SELECT customer_id, name FROM customers WHERE phone = '$CUSTOMER_PHONE'")
if [[ -z $CUSTOMER_INFO ]]; then
echo -e "\nI don't have record of that phone number, what's your name?"
read CUSTOMER_NAME
# Insertar nuevo cliente
INSERT_CUSTOMER_RESULT=$($PSQL "INSERT INTO customers(phone, name) VALUES('$CUSTOMER_PHONE', '$CUSTOMER_NAME')")
# Obtener el ID recién insertado
CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone = '$CUSTOMER_PHONE'")
else
CUSTOMER_ID=$(echo "$CUSTOMER_INFO" | cut -d'|' -f1)
CUSTOMER_NAME=$(echo "$CUSTOMER_INFO" | cut -d'|' -f2)
fi
# Solicitar el horario
echo -e "\nWhat time would you like your $(echo "$SERVICE_NAME" | sed -E 's/^ *| *$//g'), $(echo "$CUSTOMER_NAME" | sed -E 's/^ *| *$//g')?"
read SERVICE_TIME
#echo "DEBUG: CUSTOMER_ID=$CUSTOMER_ID, SERVICE_ID_SELECTED=$SERVICE_ID_SELECTED, SERVICE_TIME=$SERVICE_TIME"
# Insertar la cita
INSERT_APPOINTMENT=$($PSQL "INSERT INTO appointments(customer_id, service_id, time) VALUES($CUSTOMER_ID, $SERVICE_ID_SELECTED, '$SERVICE_TIME')")
# Mensaje final de confirmación
echo -e "\nI have put you down for a $(echo "$SERVICE_NAME" | sed -E 's/^ *| *$//g') at $SERVICE_TIME, $(echo "$CUSTOMER_NAME" | sed -E 's/^ *| *$//g')."
}
MAIN_MENU
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:136.0) Gecko/20100101 Firefox/136.0
Challenge Information:
Salon Appointment Scheduler - Build a Salon Appointment Scheduler