Skip to content

jmcanterafonseca/typescript-rest-mongoose

Repository files navigation

TypeScript REST Mongoose Challenge

Data Model

The Car data model is based on https://schema.org/Car. A Car has an internal identifier (id) which is a UUID URN automatically generated by the API implementation. In addition each Car resource has a unique vehicleIdentificationNumber that also plays the role of ObjectId in MongoDB, so that its uniqueness is preserved.

  • The vehicleIdentificationNumber must be supplied, together with brand and model when creating a new Car resource.
  • When updating an existing Car resource the vehicleIdentificationNumber must not be present.
  • Car resources are represented using JSON-LD, thus the additional @context member is present.

How to run

Prerequisites

  • docker & docker-compose
  • Node 16
  • npm 8

Steps

There is an intermediate step to create a Docker network (named data-center) on which the containers will live.

npm run docker-network
npm run start-docker

Note: The command above will build the image and compile the source within the container (it does not mean this is the best practice, though, it has been put in place to avoid possible mismatches with the tester's local node version).

Testing

Afterwards the API service will be listening to http://localhost:5000 and also a MongoDB container will be running. You can test the API Service is running properly by

curl --location --request GET 'http://localhost:5000/cars'

Stopping services

npm run stop-docker

API Definition

Tasks for further investigation

  • It would be good to automatically generate the mongoose Schema from the JSON Schema to avoid repetition and improve maintainability.
  • It would be good to incorporate functional tests to test all the API functionality, moving towards CI.
  • It would be good to rollup all the contents in a single file and find a way to minimize the container size (probably by compiling locally instead of on the container)

About

Reference Project TypeScript - REST - Mongoose

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published