This document contains the requirements for completing your interview challenge as well as instructions for setup and teardown. Read the following content carefully!
First, we'll need to navigate to the directory on the interview USB drive where the challenge files are. On a mac, you'll find it here:
cd "/Volumes/INTERVIEW/[YOUR DIRECTORY NAME]"
Next, we need to setup the challenge. You can do so by simply running a script:
cd setup && npm run setup && cd ..
The folders for each part of this challenge contain a package.json
that specifies the dependencies for that part. You can quickly install dependencies for all parts of the challenge by running this script:
cd setup && npm run install:all && cd ..
A database connection string has been set in the .env
file at the top level of this repository. You can use this to connect to the database using any client you wish.
If you would like to use Postico to access the database you can simply use the .pgfav
file in the interview root directory to automatically add the database connection configuration. Use the following command:
open postico-db-practice-a.pgfav
This challenge has three parts:
- Part 1: Create a function that uses pg-promise to execute a SQL query from within a Node.js program
- Part 2: Using Express, implement handling for a GET route that renders (returns markup for) an HTML page using a template engine (Pug or EJS)
- Part 3: Remove a row from a html page using javascript
Create a function in the file db.js
called getFlightPassengers
.
The function should accept a string parameter named flightNumber
. It should use the pg-promise
database client (already instantiated) and return a promise that resolves to the result of the query (an array of objects containing the names of all passengers on that flight. The property for the passenger name values in these objects should be called name
).
Sample result:
[ { name: 'Michael Jackson' },
{ name: 'Tito Jackson' },
{ name: 'Jackie Jackson' },
{ name: 'Baby Spice' },
{ name: 'Scary Spice' } ]
- 5: The function takes a parameter called
flightNumber
. - 5: The function executes a SQL query using
pg-promise
- 5: The query uses index variables (e.g.
$1
) to make the query dynamic - 5: The function returns a promise which resolves to the result of the query.
- 20: The result set of the SQL query includes one row containing a passenger name field for every passenger on the specified flight number.
An ER diagram has been provided that visualizes the database schema:
Implement handling for a route/endpoint GET /flight_roster
. It should accept a query string parameter flightNumber
-- a string value representing a flight number. Use the getFlightPassengers
function provided in db.js
to retrieve the list of passengers on the specified flight.
- 5: Route is a GET route
- 5: Route accesses the
flightNumber
query string parameter successfully - 5: Route uses the provided
getFlightPassengers
function to retrieve the passenger data - 10: Route passes data to the EJS or Pug template.
- 10: The template contains code to correctly render the list of passengers retrieved.
- 10: The template contains code to correctly display the text
An error occurred
in the div with the idmessage
, in the case of a server error. - 10: A
GET /flight_roster
request can be executed using a browser without error.
To start the server, run: npm start
.
In this section, the scaffolding has been created for the /flight_roster
route described in Part 2. Choose a template engine (EJS or Pug) in app.js
, then make a GET
request for the /flight_roster
resource. Include the query string flightNumber=1147A
to retrieve passengers for that specific flight.
The challenge for this section: when a user clicks the button labeled Give passenger a parachute
, one of the passengers (it doesn't matter which one) should be removed from the list. Note: The passenger only needs to be removed from the page. There is no need to update the database or communicate with the server in any way.
You may use vanilla JS or jQuery.
- 5: Code is written in
flight_roster.js
, not inline in the template file. - 10: The code uses JavaScript or jQuery to access the
Give passenger a parachute
button DOM element. - 10: The
Give passenger a parachute
button has an on click event listener. - 10: The event listener callback removes a row upon the first click.
- 10: The passenger list has one fewer row after each click.
- 10: If the list is empty when the button is clicked, the page displays a message in the div with the id
message
: "All out of passengers".
To start the server, run: npm start
.
Let's do a little cleanup:
- End the video recording (if applicable)
- From your terminal, stop any running express servers
- From your terminal,
cd
out of the usb drive directory - Quit your terminal application
- Close any browser windows pertaining to the challenge
- Remove the
Postico
entry for the database connection (if applicable) - Quit your text editor application
- Eject the USB drive (
diskutil unmount INTERVIEW
)