Giter Site home page Giter Site logo

random's Introduction

Description

This is a web service for order management for an internal team. Tech stack used:-

Nest framework

TypeScript laguage

Jest for testing

Postgresql database

Typeorm Orm

The reason of using a combination of typescript and nestjs is that it provides us to write code in a structural way. It gives us the advantage of using classes, Dtos, interfaces, modules etc. to reduces inconsistencies in the code. It allows us to keep our code well structured and maintainable.

Installation

Go to the root directory and run following command.

$ npm install
node version 16

Running the app

# development
$ npm run start:dev

Test

# unit tests
$ npm run test

Problem statement assumption

The basic assumption behind the problem statement is that there are orders of a product which belong to a unique service type. And other teams should be able to see the order information

Goal

After completion of the project there will be a fully functional internal webservice(restful architecture) available to the teams which the can use to access and edit information

Webservice overview

  1. This webservice has 2 models.
    • Order : this is considered as a document having details of a general order. Every order will have a unique id.
    • Service: this is considered as a service type to which an order can ne mapped.Every service will have a unique name.
# Order Schema
{
  id: number; (unique)
  dateTime: Date;
  totalFee: number;
  serviceId: number;
  isArchived: boolean;
  createdAt: Date;
  updatedAt: Date;
}

# Service Schema
{
  id: number; (unique)
  name: string; (unique)
  createdAt: Date;
  updatedAt: Date;
}
  1. In this webservice there are functionalities to add, update, delete, get all and get a single record. These have been implemented to both orders and services.
  2. Methods used are POST, PUT, GET, DELETE.
  3. There are in total 10 apis in the webservice 5 each for order and services.
  4. Following are the functionalities for Orders
    • addOrder > to create a new order
    • updateOrder > to update an existing order only of it was created 3 hours before.
    • getAllOrder> to fetch all the orders
    • getOrderById> to get 1 perticular order
    • deleteOrder> to delete an order
  5. Following are the functionalities for Service
    • addService > to create a new Service checking uniqueness of the service name.
    • updateService > to update an existing Service checking uniqueness of the service name.
    • getAllService> to fetch all the Services
    • getServiceById> to get 1 perticular Service
    • deleteService> to delete a Service
  6. Since all are internal apis are to be used by internal teams, all the apis are guarded with an internal api key which is kept inside .env file. You can change its value according to your convenience it is necessary to pass internal-api-key inside headers to access the apis.
  7. Jest has been used to write the test cases. to run test run npm run test

Apis overview

  1. addOrder
    • endpoint -> localhost:3000/order method POST
    curl --location --request POST 'localhost:3000/order' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json' \--data-raw '{
    "dateTime":"2022-11-01T11:11:11.111Z",
    "totalFee":4000,
    "serviceId":70
    }'
  2. updateOrder
    • endpoint -> localhost:3000/order/:id method PUT
    curl --location --request PUT 'localhost:3000/order' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json' \--data-raw '{
    "dateTime":"2022-11-01T11:11:11.111Z",
    "totalFee":4000,
    "serviceId":70
    }'
  3. getAllOrders
  • endpoint -> localhost:3000/order method Get
curl --location --request GET 'localhost:3000/order' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json'
  1. getOrderById
    • endpoint -> localhost:3000/order/:id method Get
    curl --location --request GET 'localhost:3000/order/1' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json'
  2. deleteService
  • endpoint -> localhost:3000/order/:id method Delete
    curl --location --request DELETE 'localhost:3000/order/1' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json'
  1. addService
    • endpoint -> localhost:3000/service method POST
    curl --location --request POST 'localhost:3000/service' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json' \--data-raw '{
    "name":"analysis"
    }'
  2. updateService
    • endpoint -> localhost:3000/service/:id method PUT
    curl --location --request PUT 'localhost:3000/service/8' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json' \--data-raw '{
    "name":"analysisq"
    }'
  3. getAllServices
  • endpoint -> localhost:3000/service method Get
    curl --location --request GET 'localhost:3000/service' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json
  1. getServiceById
    • endpoint -> localhost:3000/service/:id method Get
      curl --location --request GET 'localhost:3000/service/1' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json'
  2. deleteService
    • endpoint -> localhost:3000/service/:id method Delete
      curl --location --request DELETE 'localhost:3000/service/1' \--header 'internal-api-key: abcd' \--header 'Content-Type: application/json'

Important points for setup

  1. Env file has been added in the project.
  2. You will have to add a database named randomDb, run npm i and the run npm run start:dev.

random's People

Contributors

muneeb21 avatar winwr21 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.