Skip to content

joinpursuit/Web-Backend-Takehome-Coding-Challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Pursuit Logo

Web-Backend-Takehome-Coding-Challenge

Back-End coding challenge building a Raffle App with Node.js, Express.js and PostgresSQL.

Prerequisites

Getting Started

  1. Create a new Express App and give it a name. This will be for your back-end server.
  2. Setup a Postgres Database locally (or in ElephantSQL) according to the Technical requirements below.
  3. Complete your back-end server according to the Technical requirements below.

Technical Requirements

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

Recommended file structure

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

Database

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.

database tables diagram

Server

Create an express server with the following endpoints.

Endpoints

GET /raffles

Retrieve all raffles.

POST /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" 
}
GET /raffles/:id

Retrieve a single raffle by its id.

GET /raffles/:id/participants

Retrieve all user participants of a raffle.

POST /raffles/:id/participants

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",
}
PUT /raffles/:id/winner

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.

Bonus Endpoints

GET /raffles/:id/winner

Retrieve the winner of a raffle.

GET /raffles/:id?active=<false|true>

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)

Submission Guidelines

  • 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.
  • For any questions reach out to @Alejo in the Pursuit Core Workspace

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published