shirenekboyd / final-capstone-project

Restaurant Reservation System
0 stars 0 forks source link

US-07 Search for a reservation by phone number #16

Open shirenekboyd opened 2 years ago

shirenekboyd commented 2 years ago

As a restaurant manager I want to search for a reservation by phone number (partial or complete) so that I can quickly access a customer's reservation when they call about their reservation.

Acceptance Criteria

  1. The /search page will
    • [x] Display a search box <input name="mobile_number" /> that displays the placeholder text: "Enter a customer's phone number"
    • [x] Display a "Find" button next to the search box.
    • [x] Clicking on the "Find" button will submit a request to the server (e.g. GET /reservations?mobile_number=800-555-1212). then the system will look for the reservation(s) in the database and display all matched records on the /search page using the same reservations list component as the /dashboard page.
    • [x] the search page will display all reservations matching the phone number, regardless of status.
    • [x] display No reservations found if there are no records found after clicking the Find button.
shirenekboyd commented 2 years ago

Hint To search for a partial or complete phone number, you should ignore all formatting and search only for the digits. You will need to remove any non-numeric characters from the submitted mobile number and also use the PostgreSQL translate function.

The following function will perform the correct search.

function search(mobile_number) {
  return knex("reservations")
    .whereRaw(
      "translate(mobile_number, '() -', '') like ?",
      `%${mobile_number.replace(/\D/g, "")}%`
    )
    .orderBy("reservation_date");
}