No description
Find a file
2024-02-28 10:09:28 +01:00
.vscode initial commit 2024-02-27 22:09:39 +01:00
config initial commit 2024-02-27 22:09:39 +01:00
migrations initial commit 2024-02-27 22:09:39 +01:00
src initial commit 2024-02-27 22:09:39 +01:00
test-e2e initial commit 2024-02-27 22:09:39 +01:00
.env initial commit 2024-02-27 22:09:39 +01:00
.gitignore update coverage test 2024-02-28 10:09:28 +01:00
docker-compose.yml initial commit 2024-02-27 22:09:39 +01:00
jest.json update coverage test 2024-02-28 10:09:28 +01:00
nest-cli.json initial commit 2024-02-27 22:09:39 +01:00
notes.txt initial commit 2024-02-27 22:09:39 +01:00
package-lock.json initial commit 2024-02-27 22:09:39 +01:00
package.json update coverage test 2024-02-28 10:09:28 +01:00
README.md update coverage test 2024-02-28 10:09:28 +01:00
tsconfig.build.json initial commit 2024-02-27 22:09:39 +01:00
tsconfig.json initial commit 2024-02-27 22:09:39 +01:00
yarn.lock initial commit 2024-02-27 22:09:39 +01:00

How to use

Stack: NestJs + TypeORM + Postgres

Requirements

  • Docker / Docker Compose
  • Node.js 18

Installation

$ yarn

Running the app

First you need to start, migrate and seed the db :

$ yarn init-project

you can then start the server:

# development
$ yarn start

# watch mode
$ yarn start:dev

Test

To run unit tests:

# unit tests
$ yarn test

# e2e tests
$ yarn test:e2e

# test coverage
$ yarn test:cov

Database Migration

When the data schema is updated, the database needs to be synchronised with the code. This is done by creating a migration with Typeorm using the following command:

migrationName=<name> yarn migration:generate

Hiring Test

When working on the following exercise, in addition to answering the product need, to give particular attention to the following points:

  • Readability
  • Maintainability
  • Unit testing
  • Handling of corner cases
  • Error-handling

We want to compute the Agrybalise carbonfootprint of a foodproduct (e.g.: a hamCheesePizza) that we characterize by its ingredients as shown below

const hamCheesePizza = {
  ingredients: [
    { name: "ham", quantity: 0.1, unit: "kg" },
    { name: "cheese", quantity: 0.15, unit: "kg" },
    { name: "tomato", quantity: 0.4, unit: "kg" },
    { name: "floor", quantity: 0.7, unit: "kg" },
    { name: "oliveOil", quantity: 0.3, unit: "kg" },
  ],
};

The calculation of the Agrybalise carbon footprint can be described as below:

  • The Agrybalise carbon footprint of one ingredient is obtained by multiplying the quantity of the ingredient by the emission of a matching emission factor (same name and same unit).
  • The carbon footprint of the food product is then obtained by summing the carbon footprint of all ingredients.
  • If the carbon footprint of one ingredient cannot be calculated, then the carbon footprint of the whole product is set to null.

The tasks of this exercice are as follows: 1/ Implement the carbon footprint calculation of a product and persist the results in database. 2/ Implement a GET endpoint to retrieve the result. 3/ Implement a POST endpoint to trigger the calculation and the saving in the database.