# Salon Appointment 3rd and 2nd to last test not passing

**URL:** <https://forum.freecodecamp.org/t/salon-appointment-3rd-and-2nd-to-last-test-not-passing/709843>\
**Category:** General\
**Created:** [September 7, 2024, 3:21am UTC](https://forum.freecodecamp.org/t/salon-appointment-3rd-and-2nd-to-last-test-not-passing/709843 "2024-09-07T03:21:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudip00kc](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sudip00kc](https://forum.freecodecamp.org/u/sudip00kc)\
**Post date:** [September 7, 2024, 3:21am UTC](https://forum.freecodecamp.org/t/salon-appointment-3rd-and-2nd-to-last-test-not-passing/709843/1 "2024-09-07T03:21:40Z")

</div>

```auto
#!/bin/bash

PSQL="psql --username=freecodecamp --dbname=salon --tuples-only -c"

echo -e "\n ~~~~~MY SALON~~~~~"

echo -e "\nWelcome to My Salon, how can I help you?\n"

BOOK_SERVICE() {
  # Display message if provided
  if [[$1]]; then
    echo -e "\n$1"
  fi

  # Fetch and display available services
  SERVICES=$($PSQL "SELECT service_id, name FROM services")
  echo "$SERVICES" | while read SERVICE_ID BAR SERVICE_NAME; do
    echo -e "$SERVICE_ID) $SERVICE_NAME"
  done

  # Read service selected by user
  read SERVICE_ID_SELECTED

  # Check if input is a number
  if [[! $SERVICE_ID_SELECTED =~ ^[0-9]+$ ]]; then
    BOOK_SERVICE "I could not find that service. What would you like today?"
  else
    # Check if the selected service is available
    SERVICE_AVAILABILITY=$($PSQL "SELECT service_id FROM services WHERE service_id=$SERVICE_ID_SELECTED")

    # If service is not available, prompt the user again
    if [[-z $SERVICE_AVAILABILITY]]; then
      BOOK_SERVICE "I could not find that service. What would you like today?"
    else
      echo -e "\nWhat's your phone number?"
      # Read customer phone number
      read CUSTOMER_PHONE_INPUT

      # Fetch customer name using phone number
      CUSTOMER_NAME=$($PSQL "SELECT name FROM customers WHERE phone='$CUSTOMER_PHONE_INPUT'")

      # If customer does not exist, ask for the name
      if [[-z $CUSTOMER_NAME]]; then
        echo -e "\nI don't have a record for that phone number, what's your name?"
        # Read new customer name
        read CUSTOMER_NAME

        # Insert new customer into the database
        INSERT_NEW_CUSTOMER=$($PSQL "INSERT INTO customers(name, phone) VALUES('$CUSTOMER_NAME', '$CUSTOMER_PHONE_INPUT')")
      fi

      # Fetch service name using the selected service ID
      SERVICE_NAME=$($PSQL "SELECT name FROM services WHERE service_id=$SERVICE_ID_SELECTED")

      # Format customer name for display
      CUSTOMER_NAME_FORMATTED=$(echo $CUSTOMER_NAME | sed 's/ //g')

      # Format customer name for display
      SERVICE_NAME_FORMATTED=$(echo $SERVICE_NAME | sed 's/ //g')

      # Ask for appointment time
      echo -e "\nWhat time would you like your $SERVICE_NAME_FORMATTED, $CUSTOMER_NAME_FORMATTED?"
      read SERVICE_TIME_INPUT

      # Get customer ID
      CUSTOMER_ID=$($PSQL "SELECT customer_id FROM customers WHERE phone='$CUSTOMER_PHONE_INPUT'")

      # Insert appointment into the database
      INSERT_APPOINTMENT=$($PSQL "INSERT INTO appointments(time, customer_id, service_id) VALUES('$SERVICE_TIME_INPUT', $CUSTOMER_ID, $SERVICE_ID_SELECTED)")

      # Confirm the appointment
      echo -e "\nI have put you down for a $SERVICE_NAME_FORMATTED at $SERVICE_TIME_INPUT, $CUSTOMER_NAME_FORMATTED.\n"
    fi
  fi
}

BOOK_SERVICE

```

Database looks like this

```auto
salon=> \d appointments
                                            Table "public.appointments"
     Column | Type | Collation | Nullable | Default                       
----------------+----------------------+-----------+----------+-----------------------------------------------------
 appointment_id | integer | | not null | nextval('appointment_appointment_id_seq'::regclass)
 time | character varying(5) | | not null | 
 customer_id | integer | | not null | 
 service_id | integer | | not null | 
Indexes:
    "appointment_pkey" PRIMARY KEY, btree (appointment_id)
Foreign-key constraints:
    "appointment_customer_id_fkey" FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
    "appointment_service_id_fkey" FOREIGN KEY (service_id) REFERENCES services(service_id)

salon=> 

                                         Table "public.customers"
   Column | Type | Collation | Nullable | Default                     
-------------+-----------------------+-----------+----------+------------------------------------------------
 customer_id | integer | | not null | nextval('customers_customer_id_seq'::regclass)
 name | character varying(30) | | not null | 
 phone | character varying(15) | | not null | 
Indexes:
    "customers_pkey" PRIMARY KEY, btree (customer_id)
    "customers_phone_key" UNIQUE CONSTRAINT, btree (phone)
Referenced by:
    TABLE "appointments" CONSTRAINT "appointment_customer_id_fkey" FOREIGN KEY (customer_id) REFERENCES customers(customer_id)

                                         Table "public.services"
   Column | Type | Collation | Nullable | Default                    
------------+-----------------------+-----------+----------+----------------------------------------------
 service_id | integer | | not null | nextval('services_service_id_seq'::regclass)
 name | character varying(30) | | not null | 
 price | integer | | not null | 
Indexes:
    "services_pkey" PRIMARY KEY, btree (service_id)
    "services_name_key" UNIQUE CONSTRAINT, btree (name)
Referenced by:
    TABLE "appointments" CONSTRAINT "appointment_service_id_fkey" FOREIGN KEY (service_id) REFERENCES services(service_id)

salon=> 

```

I tried increasing time out in test/utils.js and also a code from someone that they had mentioned passed the test but both didn’t worked out.

---

<div class="post-metadata">

**Author:** ![hbar1st](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbar1st/32/372649_2.png) [@hbar1st](https://forum.freecodecamp.org/u/hbar1st)\
**Post date:** [September 7, 2024, 8:48am UTC](https://forum.freecodecamp.org/t/salon-appointment-3rd-and-2nd-to-last-test-not-passing/709843/2 "2024-09-07T08:48:52Z")

</div>

Your time field should be varchar 10 because the test uses more than 5 spaces for it.

---

<div class="post-metadata">

**Author:** ![sudip00kc](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sudip00kc](https://forum.freecodecamp.org/u/sudip00kc)\
**Post date:** [September 10, 2024, 12:32pm UTC](https://forum.freecodecamp.org/t/salon-appointment-3rd-and-2nd-to-last-test-not-passing/709843/3 "2024-09-10T12:32:55Z")

</div>

thank you very much,that did the work. Where is it mentioned that VARCHAR needs to be more that 5?

---

<div class="post-metadata">

**Author:** ![hbar1st](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hbar1st/32/372649_2.png) [@hbar1st](https://forum.freecodecamp.org/u/hbar1st)\
**Post date:** [September 10, 2024, 12:34pm UTC](https://forum.freecodecamp.org/t/salon-appointment-3rd-and-2nd-to-last-test-not-passing/709843/4 "2024-09-10T12:34:46Z")

</div>

I don’t think it is mentioned. If you search the forum though, you will see many posts about similar issues.

---

<div class="post-metadata">

**Author:** ![sudip00kc](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sudip00kc](https://forum.freecodecamp.org/u/sudip00kc)\
**Post date:** [September 10, 2024, 12:46pm UTC](https://forum.freecodecamp.org/t/salon-appointment-3rd-and-2nd-to-last-test-not-passing/709843/5 "2024-09-10T12:46:39Z")

</div>

Ohh I only found post related to timeout,thank you anyways.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [March 12, 2025, 12:47am UTC](https://forum.freecodecamp.org/t/salon-appointment-3rd-and-2nd-to-last-test-not-passing/709843/6 "2025-03-12T00:47:31Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
