Code Monkey home page Code Monkey logo

onlinestoreudacity's Introduction

#Main function

the project main functionality is to make a Storefront Backen projetc ##########################################################
#Usage of API

Products

  • Index [token required] [GET] /products
  • Show [token required] [GET] /products/:id
  • Create [token required] [POST] /products (body: name, price, category)
  • Delete [token, and admin user required] [DELETE] /products/:id
  • Update [token, and admin user required] [PATCH] /products/:id (body: name, price, category)
  • Top 5 most popular products [token required] [GET] /mostPopularProducts
  • Products by category [token required] [GET] /productsByCategory/:category
  • Products in orders [token required] [GET] /productsInOrders

Users

  • Index [token required] [GET] /users
  • Show [token required] [GET] /users/:id
  • Create [token not required] [POST] /users (body: first_name, last_name, user_name, role, password)
  • Delete [token, and admin user required] [DELETE] /users/:id
  • Update [token, and admin user required] [PATCH] /users/:id (body: first_name, last_name, user_name, role, password)
  • Get token[send "username" and "password" as a json data in body] [POST] /users/login
  • 5 most recent purchases orders for users [token required] [GET] /mostRecentPurchases/:id

Orders

  • Index [token required] [GET] /orders
  • Show [token required] [GET] /orders/:id
  • Create [token required] [POST] /orders (body: status, user_id)
  • Delete [token, and admin user required] [DELETE] /orders/:id
  • Update [token, and admin user required] [PATCH] /orders/:id (body: status, user_id)
  • Current Order by user [token required] [GET] /ordersCurrentOrder/:id
  • Completed Orders by user [token required] [GET] /ordersCompletedOrders/:id
  • Add products in Order [token required send "product_id" and "quantity" as a json data in body] [GET] /orders/:id/products (body: quantity, product_id, order_id)

########################################################## #Technologies Used

Your application must make use of the following libraries:

  • Postgres for the database
  • Node/Express for the application logic
  • dotenv from npm for managing environment variables
  • db-migrate from npm for migrations
  • jsonwebtoken from npm for working with JWTs
  • jasmine from npm for testing

I have written some scripts that needs to be run scripts "testJasmine": "cross-env ENV=test jasmine" "devJasmine": "jasmine" "testdb-reset": "db-migrate reset --config ./database.json --e test" "testdb-up": "db-migrate --config ./database.json --e test up" "devdb-up": "db-migrate up --config ./database.json --e dev" "devdb-reset": "db-migrate reset --config ./database.json --e dev" "build": "npx tsc" "lint": "eslint . --ext .ts" "prettier": "prettier --config .prettierrc src/**/*.ts --write" "start": "nodemon src/server.ts" "watch": "tsc-watch --esModuleInterop src/server.ts --outDir ./dist --onSuccess "node ./dist/server.js"" "test": "db-migrate reset --config ./database.json --e test && set NODE_ENV=test&& npm run build && npm run testdb-up && jasmine"


I have used some dependencies "devDependencies": npm i --save-dev @types/[email protected] npm i --save-dev @types/[email protected] npm i --save-dev @types/[email protected] npm i --save-dev @types/[email protected] npm i --save-dev @types/[email protected] npm i --save-dev @types/[email protected] npm i --save-dev @types/[email protected] npm i --save-dev @types/[email protected] npm i --save-dev @types/[email protected] npm i --save-dev @typescript-eslint/[email protected] npm i --save-dev @typescript-eslint/[email protected] npm i --save-dev [email protected] npm i --save-dev [email protected] npm i --save-dev [email protected] npm i --save-dev [email protected] npm i --save-dev [email protected] npm i --save-dev [email protected] npm i --save-dev [email protected] npm i --save-dev [email protected] npm i --save-dev [email protected] npm i --save-dev [email protected] npm i --save-dev [email protected]

"dependencies": npm i [email protected] npm i [email protected] npm i [email protected] npm i [email protected] npm i [email protected] npm i [email protected] npm i [email protected] npm i [email protected] npm i [email protected] npm i [email protected] npm i [email protected] npm i [email protected]

########################################################## #Tests

-Test cases have been added for all functions and endpoints you can run it by: -reset migrations first [test database: testdb-reset, and dev database: devdb-reset] -run all migrations up [test database: testdb-up, and dev database: devdb-up] -run jasmine test [test database: testJasmine, and dev database: devJasmine] ########################################################## #How it works

-First step you should Create databases you can create one for development and the other for test, you can do this by pgadmin or by command line -Please add all psql data in .env file (POSTGRES_DB, POSTGRES_TEST_DB, POSTGRES_USER, POSTGRES_PASSWORD) -NODE_ENV=dev for dev database, and NODE_ENV=test for test database -To use password hashing, and token authontication change your security data in .env file (BCRYPT_PASSWORD, SALT_ROUNDS, TOKEN_SECRET) -To add all tables in the created database you need to run all migrations up files [test database: testdb-reset, and dev database: devdb-reset] -Our used port is 3000 -Database port number is the Default port 5432 -Then you can use any endpoint as described to perform an action on the tables for examples: -http://127.0.0.1:3000/users/login [POST] (body: "username" and "password") to get token -CREATE(POST) Or UPDATE(PATCH): for update we will add /:id to update one element data by the added id -http://127.0.0.1:3000/users [POST/PATCH] (body: "first_name", "last_name", "user_name", "role", and "password") -http://127.0.0.1:3000/orders [POST/PATCH] (body: "status" and "user_id") -http://127.0.0.1:3000/products [POST/PATCH] (body: "name", "price" and "category") -http://127.0.0.1:3000/orders/:id/products [POST] (body: "quantity", and "product_id") and send order id in the url -INDEX Or SHOW: it will get all data in the table, and you can add /:id to show one element data by the added id -http://127.0.0.1:3000/users [GET] -http://127.0.0.1:3000/orders [GET] -http://127.0.0.1:3000/products [GET] -http://127.0.0.1:3000/ordersCurrentOrder/:id [GET] Current Order by user -DELETE: -http://127.0.0.1:3000/users/:id [DELETE] -http://127.0.0.1:3000/orders/:id [DELETE] -http://127.0.0.1:3000/products/:id [DELETE]

########################################################## #extra

-add all CRUD -http://127.0.0.1:3000/ordersCompletedOrders/:id [GET] Completed Orders by user -http://127.0.0.1:3000/mostPopularProducts [GET] Top 5 most popular products -http://127.0.0.1:3000/productsByCategory/:category [GET] Products by category -http://127.0.0.1:3000/productsInOrders [GET] Products in orders -http://127.0.0.1:3000/mostRecentPurchases/:id [GET] 5 most recent purchases orders for users

########################################################## #commands to run

npm run build npm run prettier npm run lint npm run test npm run start npm run watch ##########################################################

onlinestoreudacity's People

Contributors

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