Giter Site home page Giter Site logo

watch-api's Introduction

⌚️ Watch Online Shop API

Simple API built with nest.js, GraphQL, TypeORM and PostgreSQL for showcasing operations of watch online shop.

The project contains four modules to showcase a simple checkout action:

  • watch
  • discount
  • user
  • cart

Considering that the API would be consumed by a "dumb" client, the backend holds the state of a user's cart. So instead of creating an endpoint that calculates a total cost of a list of watches the client can access and update the cart's state through the respective queries/mutations. To obtain the total of a user's cart the following query can be used:

query {
  cart(id: 'cart-id') {
    total
  }
}

To add items to a user's cart and obtain the updated total of the cart, the client can use the following mutation:

mutation {
  addCardItem(id: 'card-id', newItem: 'watch-id') {
    total
  }
}

🏃🏼‍♀️ Run

To run the API a docker-compose is provided. First create a .env file, add the vars from .env.example and source the .env file locally for the PostgreSQL service:

source .env

The run the following command to fire up the API and a PostgreSQL:

docker-compose up

The GraphQL playground can be accessed on http://localhost:3000/graphql.

To seed the db run the seed query in the playground:

query {
  seed
}

This will create all necessary items to test out all endpoints. The seeded data can be found in seed.resolver.ts.

🧪 Tests

For tests the Jest test framework is used. Before running build, tests are automatically run when building the docker image.

Tests can be run locally with the following command:

npm run test

As of now only the cart.service.spec.ts tests are implemented and the endpoint for creating a new cart item considered to contain the vital business logic is tested. Tests for the other services would be written in the same manner.

👷🏼‍♀️ Room for Improvement

There are several things that could be improved here to enhance usability of the API:

  • Increase test coverage
  • Add authorization and authentication for API
  • Add user management
  • Refactor watch module to be product module to achieve a more generic data model
  • Add error handling for adding undefined products/watches to cart
  • Add and endpoint to remove items from the cart
  • Refactor cart item data structure to already include quantity in the structure (will remove computational expensive calculations)

watch-api's People

Contributors

allenfang avatar alsoicode avatar bashleigh avatar beeman avatar ben-webantic avatar blazeu avatar brunnerlivio avatar dependabot[bot] avatar e-watson avatar elylucas avatar fanybook avatar hiagodotme avatar jajaperson avatar kamilmysliwiec avatar konradlinkowski avatar lambdacasserole avatar leenahere avatar maximzinovik avatar mchelen avatar nosfistis avatar progral avatar renovate-bot avatar rpihlak avatar rubencodeforges avatar rubiin avatar sacro avatar schinvendy avatar whitekiwi avatar xorik avatar yurykozhenov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.