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.
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
- Install node - recommend using nvm
- Install libraries: run the following in your terminal
npm install
- Setup the SQLLite database one time
npm run prisma:setup
- Start the server
npm run dev
You can test the using swagger API
- Load the swagger UI in your browser at the url `http://localhost:5001/docs
- Test the /benefits GET API endpoint
- Run the tests
npm test
The tests will fail until you implement the 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.
- 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
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
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
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
- 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