Giter Site home page Giter Site logo

siva-mummadisetti / nodejs-stock-trades-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from anirbandgit/nodejs-stock-trades-api

0.0 0.0 0.0 44 KB

Hacker rank Test GL - Concepts : adding integer in sequence 1 to n automatically in mongo document, validating some conditions before insert into DB, using query parameters of the request URL, diff code struct.

Shell 2.08% JavaScript 97.92%

nodejs-stock-trades-api's Introduction

Stock Trades API Hard

Data:

Example of a trade data JSON object:

{
    "id":1,
    "type": "buy",
    "user_id": 23,
    "symbol": "ABX",
    "shares": 30,
    "price": 134,
    "timestamp": 1531522701000
}

Project Specifications:

The task is to implement a model for the trade object and the REST service that exposes the /trades endpoint, which allows for managing the collection of trade records in the following way:

POST request to /trades:

  • creates a new trade
  • expects a JSON trade object without an id property as a body payload. If the shares value is out of accepted range [1, 100], or the type value is invalid (i.e. not 'buy' or 'sell'), the API must return error code 400. Besides those cases, you can assume that the given payload is always valid.
  • adds the given trade object to the collection of trades and assigns a unique integer id to it. The first created trade must have id 1, the second one 2, and so on.
  • the response code is 201, and the response body is the created trade object

GET request to /trades:

  • returns a collection of all trades
  • the response code is 200, and the response body is an array of all trades objects ordered by their ids in increasing order
  • optionally accepts query parameters type and user_id, for example /trades?type=buy&&user_id=122. All these parameters are optional. In case they are present, only objects matching the parameters must be returned.

GET request to /trades/<id>:

  • returns a trade with the given id
  • if the matching trade exists, the response code is 200 and the response body is the matching trade object
  • if there is no trade with the given id in the collection, the response code is 404 with the body having the text ID not found

DELETE, PUT, PATCH request to /trades/<id>:

  • the response code is 405 because the API does not allow deleting or modifying trades for any id value

Note:

You are expected to choose the ORM you want to use and initialize the connection of the Database in the file connection.js. The following ORMs/Databases are available for use out of the box:

  1. Sequelize with SQLITE
  2. Mongoose with MongoDB

Environment

  • Node Version: ^12.18.2
  • Default Port: 8000

Read Only Files

  • test/*

nodejs-stock-trades-api's People

Contributors

anirbandgit 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.