Skip to content

focusconsulting/focus-exercise-backend-typescript-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Focus Backend Engineer Exercise - Typescript/Node/Express

Overview

This is a backend exercise using typescript, node, and express.

Key Libraries:

Recommended approach:

  • Push this directory to a new github repository (guide)
  • For each exercise, create a branch and pull request (PR) and merge your PR into main for your repository
  • Exercises involve implementing code and then verifying that the written test cases pass as expected.

Structure

Partial code structure reflecting relevant folders and files for the exercise

ROOT FOLDER
  prisma/
    schema.prisma - Database models, new models should be added here    
    dev.db - the SQLLite database file
    seed.ts - file to seed the database with initial data
    migrations/ - SQL migration files capturing changes to the database over time    
  src/
    index.ts - express api entry point
    app.ts - api routes live here
    swagger-output.json - the generated openapi file
  tests/
    api.test.ts

Setup

  1. Install node - recommend using nvm
  2. Install libraries: run the following in your terminal
npm install
  1. Setup the SQLLite database one time
npm run prisma:setup
  1. Start the server
npm run dev

You can test the using swagger API

  1. Run the tests
npm test

The tests will fail until you implement the exercises.

Exercises

The first two exercises have tests written that are expected to pass. For the 3rd and 4th exercise, please write any tests you feel are necessary to confirm the working functionality.

Bonus points: create swagger documentation for the last two exercises.

1. Implement a GET employee endpoint

Acceptance Criteria

  • As a user I would like to retrieve a user by ID with fields:
    • id
    • first_name
    • last_name
    • date_of_birth
  • I should not be able to see the employee's secret
  • If the ID does not exist in the DB, I expect to receive a 404

2. Implement a PATCH employee endpoint

Acceptance Criteria:

  • As a user, I should be able to change an employees first and last name
    • The first and last name must be at least 1 character long and cannot be empty _ As a user, I would like to receive a 400 status and the relevant error if the request is invalid
  • As a user, I should receive a 404 if the ID of the employee to patch does not exist

3. Implement a POST application endpoint

Acceptance Criteria:

  • As a user, I should be able to POST a new application with the following fields
    • leave_start_date
    • leave_end_date
    • the ID of an employee
  • I should receive a 400 if the POST body is invalid
    • Missing fields
    • Employee ID does not exist

4. Implement a GET application by employee id, first or last name

Acceptance Criteria:

  • As a user, I would like to be able to search for applications
    • I should be able to search by either first name, last name or employee ID
    • If I don't provide any search parameters, I should get all the applications
  • As a user, I would like to have paginated results returned

FAQ

  • How do I reset the database? Delete the app.db file and run npm run prisma:reset
  • How do I see an example response? Test the /benefits API in the swagger UI
  • How do I create new tables from new models? New tables can be generated by running npm run prisma:migrate
  • How do I see my database entries? Run npm run prisma:studio
  • How do I regenerate the swagger documentation? Run npm run gen:swagger then restart your server

About

Focus - Backend Engineer Exercise using Typescript & Express

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published