Back-End coding challenge building a Raffle App with Node.js, Express.js and PostgresSQL.
- Node.js installed
- PostgresSQL installed
- Or you can use a managed PostgresSQL database from ElephantSQL (5mins setup, no installation of Postgres needed)
- Read How to create a Postgres Database in ElephantSQL.com
- You can sign up with a Google or GitHub Account
- Or you can use a managed PostgresSQL database from ElephantSQL (5mins setup, no installation of Postgres needed)
- A PostgresSQL Client installed to connect to and set up your database
- Mac Postico or Psquel
- Mac/Windows/Linux Beekeeper Studio
- Postman installed to test out your endpoints.
- Create a new Express App and give it a name. This will be for your back-end server.
- You may use the express-generator to create your express app scaffolding
- Setup a Postgres Database locally (or in ElephantSQL) according to the Technical requirements below.
- Complete your back-end server according to the Technical requirements below.
Your job is to create a back-end server and database for a Raffle application. Users are able to:
- Create raffles
- List all raffles
- Add participants users to raffles
- Draw a winner from a raffle
back-end
├── app.js
├── db/ # folder with your db setup and queries
├── package.json
├── README.md
└── routes/
└── raffles.js
* Does not have to match exactly
You should have at least two database tables to store the information for this app. The diagram below shows tables users
and raffles
and their relationships.
Create an express server with the following endpoints.
Retrieve all raffles.
Post a new raffle. The JSON body to send in the request should include a name
and secret_token
property.
Example POST body:
{
"name": "My first Raffle",
"secret_token": "s3CrE7"
}
Retrieve a single raffle by its id.
Retrieve all user participants of a raffle.
Sign up a participant to a raffle given a raffle id. The JSON body to send must include firstname
, lastname
, and email
.
phone
is optional
email
should be unique to protect from the same user signing multiple times for the same raffle.
Example body:
{
"firstname": "Jane",
"lastname": "Doe",
"email": "jdoe@email.com",
"phone": "+1 (917) 555-1234",
}
Selects the winner at random picking from the users that are signed up for the raffle specified by id and return it. A winner will be picked only if the request body includes a secret token that matches the token used when the raffle was created via POST /raffles
. If the token is not present or doesn't match return an error message.
Example POST body:
{ "secret_token" : "s3CrE7" }
If drawing a winner is successful return the winner user. For example:
{
"id": 2,
"raffle_id": 1,
"firstname": "John",
"lastname": "Snow",
"email": "jblizzard@email.com",
"phone": null,
"registered_at": "2021-05-22T15:43:52.647Z"
}
Note: If a winner is attempted to be picked multiple times don't allow it and return the existing winner instead. Multiple identical PUT request should have the same result, this is the definition of idempotence.
Retrieve the winner of a raffle.
Using a query param active
, return raffles that are "active" (active=true
), meaning they don't have a winner yet or raffles that already have a winner (active=false
)
- This challenge would take ~7 hours to complete, so allocate your time appropriately.
- You must submit your solution no later than Monday, May 31st at 11:59pm.
- Submit your code compressed in a zip file via the submission form
- Make sure to remove your
node_modules/
before compressing. - Your code must include a README file with instructions on how to run your project.
- Make sure to remove your
- For any questions reach out to @Alejo in the Pursuit Core Workspace