Git Product home page Git Product logo

express-backend-project's Introduction

Setup

  • Clone https://github.com/MeshalAl/Express-backend-project.git
  • npm install to install dependencies.
  • Create a local PSQL database.
  • Create a .env file, edit the brackets <> with your values:
DB_USER = <your db user>
DB_PASSWORD = <your db password>

DB_HOST = <localhost | your db host>
DB_PORT = <5432 | your db port>

DB_PRODUCTION = production_db
DB_TEST = test_db
DB_DEV = dev_db

ENV = 'dev'

SALT = <Int>
PEPPER = <String>
TOKEN_SECRET = <String>

Database setup

CREATE USER <your_db_user> WITH PASSWORD <'your password'>;

Create Databases:
CREATE DATABASE test_db;
CREATE DATABASE dev_db;

Granting access to users:

GRANT ALL PRIVILEGES ON DATABASE test_db TO <your_db_user>;
GRANT ALL PRIVILEGES ON DATABASE dev_db TO <your_db_user>;

Ports used: Database: 5432
Backend: 3000

Commands:

start nodemon:
npm run start

start jasmine tests & db-migrates on windows:

npm run test-windows for windows.
npm run test-linux for linux.

Endpoints:

Users:

Create:
post on localhost:3000/api/users Body format:

{
    "firstname": "value",
    "lastname": "value",
    "password": "value"
}

Returns

{
    "user_id": 1,
    "firstname": "value",
    "lastname": "value",
    "password": "hashed_password"
}

Authenticate:
post on localhost:3000/api/users/auth

Body format:

{
    "user_id": 1,
    "password": "value"
}

Returns: "TOKEN"

User index:
get on localhost:3000/api/users
Autherization header: "bearer TOKEN"
Returns:

[
    {
        "user_id": 1,
        "firstname": "User firtname",
        "lastname": "User lastname"
    },
    ...
]

User by id:
get on localhost:3000/api/users/[user id: int]
Autherization header: "bearer TOKEN"
Returns:

{
    "user_id": 1,
    "firstname": "User firtname",
    "lastname": "User lastname"
}

Products:

Create:
post on localhost:3000/api/products
Autherization header: "bearer TOKEN"

Body format:

{
    "product_name": "product name",
    "price": 29.59,
    "category": "category name: optional"
}

Returns:

{
    "product_id": 1,
    "product_name": "product name",
    "price": 29.59,
    "category": "category name: optional"
}

Index of products:
get on localhost:3000/api/products

Returns:

[
    {
      "product_id": 1,
      "product_name": "product name",
      "price": 29.59,
      "category": "category name: optional"
    },
    ...
]

Product by id:
get on localhost:3000/api/products/[product_id]

Returns:

{
  "product_id": 1,
  "product_name": "product name",
  "price": 29.59,
  "category": "category name: optional"
}

Orders:

Create Order:
post on localhost:3000/api/orders
Autherization header: "bearer TOKEN"
Body format:

{
    "Products": [ 
        { "product_id": 1, "quantity": 4},
        ...
    ]
}

Returns:

[
    {
        "order_id": 1,
        "user_id": 1,
        "product_name": "test product",
        "quantity": 4,
        "price": 29.59,
        "status": "active",
        "order_date": "2023-01-02T19:33:32.388Z"
    },
    ...
]

index of current user's order:
get on localhost:3000/api/orders
Autherization header: "bearer TOKEN"

Returns:

[
    {
        "order_id": 1,
        "user_id": 1,
        "product_name": "test product",
        "quantity": 4,
        "price": 29.59,
        "status": "active",
        "order_date": "2023-01-02T19:33:32.388Z"
    },
    ...
]

get current user's order by id:
get on localhost:3000/api/orders/[order_id]
Autherization header: "bearer TOKEN"

Returns:

[
    {
        "order_id": 1,
        "user_id": 1,
        "product_name": "test product",
        "quantity": 4,
        "price": 29.59,
        "status": "active",
        "order_date": "2023-01-02T19:33:32.388Z"
    },
    ...
]

Complete user's order:
post on localhost:3000/api/orders/complete/
Autherization header: "bearer TOKEN"

Body format:

{
  "order_id": 1,
  "all" [Optional]: true | false
}

Returns:

[
    {
        "order_id": 1,
        "user_id": "1",
        "status": "completed",
        "order_date": "2023-01-02T19:33:32.388Z"
    },
    ...
]

Order history:
get on localhost:3000/api/orders/history
Autherization header: "bearer TOKEN"

Returns:

[
    {
        "order_id": 1,
        "user_id": 1,
        "product_name": "test product",
        "quantity": 4,
        "price": 29.59,
        "status": "completed",
        "order_date": "2023-01-06T19:33:32.388Z"
    },
    ...
]

express-backend-project's People

Contributors

meshalal avatar christa-cheung avatar berkeleycole avatar uanjali avatar sudkul avatar mohassn 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.