Code Monkey home page Code Monkey logo

product-rating-app's Introduction

A sample project in Express, which shows how to transfer global variables like db connection, even when you are running some script which might require to use those db variables.

It also shows a sample reward system

Server Node.js โšก๏ธ DB Mongo ๐Ÿš€

Design Philosphy

  1. The system is comprised of 4 tables, namely the User, Product, Order and Rewards
  2. User table is because which user gave the rating
  3. For which Product,
  4. Against what Order
  5. What he rated.
  6. We first save the rating for a particular product against and order and user in our reward table.
  7. Next we try to fetch the product and we can see it gives a ratings and rating object. Ratings is an obj which tells like 4 people 1 star, 5 people 2 star and the rating gives aggregated value.

To get started

yarn

node one-time-scripts/create-init-data.js

Take a productId from the rewards array

call this API http://localhost:8082/api/Product?productId=<your_product_id>

this should return you the product data with the ratings obj and rating

Watch out for

  1. How I have used require.main === module a very interesting thing, very few people use
  2. everything using ENV variables
  3. dynamically creating models using filename
  4. using enums to enforce data in mongoose

product-rating-app's People

Watchers

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