Salon Appointment Scheduler: 2 Tests for adding rows not passing

I’m having an issue that appears identical to that in this thread from 2023. All of the tests are passing, except for the two near the end about inserting the row into the appointments table. The inserts are working when I check the table, so I can’t figure out why the tests won’t pass.

Code so far

salon.sh

#! /bin/bash
PSQL="psql -X --username=freecodecamp --dbname=salon --tuples-only -c"
SERVICES=$($PSQL "SELECT * FROM services;")

MAIN_MENU() {
  # Print services
  echo "$SERVICES" | while read SERVICE_ID BAR SERVICE_NAME
  do
    echo -e "$SERVICE_ID) $SERVICE_NAME"
  done
  # Get user input
  echo -e "\nPick a service:"
  read SERVICE_ID_SELECTED
  # If selection not a number
  if [[ ! $SERVICE_ID_SELECTED =~ ^[0-9]+$ ]]
  then
    # Send back to main menu
    MAIN_MENU
    return
  fi
  # If selection not a valid number
  SERVICE_AVAILABLE=$($PSQL "SELECT service_id FROM services WHERE service_id='$SERVICE_ID_SELECTED';")
  if [[ ! $SERVICE_AVAILABLE =~ $SERVICE_ID_SELECTED ]]
  then
    # Send back to main menu
    MAIN_MENU
    return
  fi
  BOOKING $SERVICE_ID_SELECTED
}

BOOKING() {
  SERVICE_ID=$1
  echo "You picked a $SERVICE_ID"
  echo "Enter your phone: "
  read CUSTOMER_PHONE
  # If phone not already in db
  EXISTING_PHONE=$($PSQL "SELECT phone FROM customers WHERE phone='$CUSTOMER_PHONE';")
  if [[ ! $EXISTING_PHONE =~ $CUSTOMER_PHONE ]]
  then
    # Prompt name
    echo "Enter your name: "
    read CUSTOMER_NAME
    # Add new customer to db
    RESULT=$($PSQL "INSERT INTO customers(phone, name) VALUES('$CUSTOMER_PHONE', '$CUSTOMER_NAME');")
  else
    CUSTOMER_NAME=$($PSQL "SELECT name from customers where phone='$CUSTOMER_PHONE';")
    # Strip whitespace from db query result
    CUSTOMER_NAME=$(echo $CUSTOMER_NAME | sed -E 's/ *$|^ *//g')
  fi
  # Get customer ID
  CUSTOMER_ID=$($PSQL "SELECT customer_id from customers where phone='$CUSTOMER_PHONE';")
  # Strip whitespace from db query result
  CUSTOMER_ID=$(echo $CUSTOMER_ID | sed -E 's/ *$|^ *//g')
  # echo $CUSTOMER_IDS | while read CUSTOMER_ID
  # echo $CUSTOMER_ID
  # Prompt time
  echo "What time for your appointment?"
  read SERVICE_TIME
  # Create new appointment
  # echo "'$CUSTOMER_ID', '$SERVICE_TIME', '$SERVICE_ID'"
  RESULT=$($PSQL "INSERT INTO appointments(customer_id, time, service_id) VALUES('$CUSTOMER_ID', '$SERVICE_TIME', '$SERVICE_ID');")
  # Print message
  SERVICE=$($PSQL "SELECT name from services where service_id='$SERVICE_ID';")
  # Strip whitespace from db query result
  SERVICE=$(echo $SERVICE | sed -E 's/ *$|^ *//g')
  echo "I have put you down for a $SERVICE at $SERVICE_TIME, $CUSTOMER_NAME."
}

MAIN_MENU

Test status:

CodeRoad:

customers table after running script according to failing tests

salon=> SELECT * FROM customers;
 customer_id |    phone     | name  
-------------+--------------+-------
           6 | 555-555-5555 | Fabio
(1 row)

appointments table after running script according to failing tests

salon=> SELECT * FROM appointments;
 appointment_id | customer_id | time  | service_id 
----------------+-------------+-------+------------
              1 |           6 | 10:30 |          1
              2 |           6 | 11am  |          2
(2 rows)

System info

Browser Chrome Version 122.0.6261.131 (Official Build) (64-bit)

OS

Edition Windows 10 Home
Version 22H2
OS build 19045.4170
Experience Windows Feature Experience Pack 1000.19054.1000.0

Challenge

Build a Salon Appointment Scheduler

Hey, did you find any way to solve this problem. I am also facing the exact same issue.

Sorry, I never got any help and was unable to resolve it.

I just tried your script using my own SQL dump on a fresh workspace and it passed for me. Try it again on a fresh DB with only the appointments added to the appointment table. I wonder if maybe the fact your customer entry is not customer_id = 1 is doing something weird with the tests. The only other thing I can think of is maybe your ‘time’ column needs to be after ‘service_id’ but the other post you referenced didn’t have that so idk… hope that works

@shahzadch

Hey, I got this issue fixed by increasing my time VARCHAR length from 5 to 10 in appointments table, in database schema. And it worked fine and passed all the tests including the two u mentioned. Try doing it and i hope it works for you as well

@aaron-sandoval
@SpookyBlump

1 Like

Yep, changing the VARCHAR length worked for me too, thanks for the tip!

1 Like