Technical task as a part of interview process. Full task definition was not provided intentionally.
Task is to create a backend API that serves shipment data and provides current weather conditions at user's location.
Use data from assets/seed.csv as initial set of data for this task.
- What does mean
weather for users location? - Not clear about requirement for status of shipments. Do we need it?
- Why zip codes and locations don't have match in some records in initial dataset?
Solution is based on given task definition and csv file.
The idea was to create multiple entities in relational database, like:
artcile- article information with pricecarrier- carrier informationshipment- information about shipments, and potentially with state, if neededmany-2-many-articles-shipments-csvfile describes such model of relations, plus this table containsquantityinformation for each article in each shipment
Weather information can be fetched on the fly for each location. There are a lot of ways to optimize this process but I chose in-memory cache with TTL. With the given solution it is not problem to connect third party key-value storages like Redis for this cache.
For status of the shipment we can add additional field to our shipment entity and update it based on changes in delivery process. All changes can be stored as events separately in RDMS or NoSQL storage depends on requirements.
assets/ - static files
config/ - config files for nest.js
prisma/ - prisma related stuff
src/
⋅⋅⋅middleware/ - middleware
⋅⋅⋅pipes/ - nestjs pipes for transformation and validation
⋅⋅⋅resources/ - core components of the nestjs app
test - e2e tests
GET /articles/{SKU} - article details for the given SKU, where SKU is the Stock Keeping Unit of the article
POST /articles - create a new article
GET /carriers - list of supported carriers
GET /weather/{ZIP} - weather details for the given location as is from external service, ZIP is the zip code of location
GET /shipments/{TRACKING_NUMBER} - all shipment details with (if available) the current weather information about destination location, TRACKING_NUMBER is a tracking number
POST /shipments - create a new shipment
$ npm install# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:covThis project uses Prisma library to interact with databases and Postgres as database.
Do the following to enable database:
- create
.envfile in the root folder:
DATABASE_URL=<put here URI to your postgres database in the following format "postgresql://postgres:@localhost:5432/postgres">
- run
npx prisma migrate devto create a database and seed initial data
This app uses free plan of OpenWeatherMap service for weather information.
Do the following to enable weather information:
- update
WEATHER_API_KEYvalue inconfig/.env.local