Skip to content

irsyaadbp/Point-Of-Sales-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Point Of Sales RESTful API

Overview

List of Contents

Introduction

Point of Sales API is an API that helps users to run their trading business. There're some features included in the API. User can handle management stock of product and store the order transaction

Built With

Node.js Express.js MySQL body-parser morgan dotenv cors jsonwebtoken

Getting Started

Requirements

  1. Node Js
  2. NPM
  3. Postman

Installation

  1. Clone or download this repository
  2. Open app's directory in CMD or Terminal.
  3. Type in Terminal npm i or npm install to install the required packages.
  4. Make a new file, .env and setup the file. instruction here
  5. Turn on Web Server and MySQL, (Also can be done with third-party tools like XAMPP, WAMP, etc)
  6. Setup the database. instruction here
  7. Open Postman desktop application or Chrome web extension (Install Postman if you haven't yet) or you can use Insomnia
  8. Choose HTTP Method and enter the request URL.(i.e. localhost:5000/product)
  9. Check all Endpoints here

Setup .env file

Duplicate .env.example file to .env on code editor and change the variable or copy the code below :

DB_HOST = 'localhost'
DB_USER = 'username'
DB_PASSWORD = 'password'
DB_DATABASE = 'database'
PORT = 5000
SECRET_KEY = 'JFDFHSKFJHSKFHSDFKSDFJKSDF'

Setup Database

You can import file database.sql to phpmyadmin.

Endpoints

IMPORTANT! All endpoint except Login and Register must have header :

  • Content-Type : application/json
  • x-access-token: token

Homepage

  • Request : GET /

  • Response :

    {
        "message": "Welcome to Point Of Sales RESTful API, You can read the documentation at README.md",
        "author": "Irsyaad Budi Prasetianto",
        "email": "irsyaad.budip@gmail.com",
        "github": "github.com/irsyaadbp"
    }
    

User

  • Register user
    • Request : POST /user/register
      {
          "username": "irsyaadbp",
          "password": "12345678",
          "user_role": "administrator"
      }
      
    • Response :
      {
          "status": 200,
          "result": "User created successfully"
      }
      
  • Login User
    • Request : POST /user/login
      {
          "username": "irsyaadbp",
          "password": "12345678"
      }
      
    • Response :
      {
          "status": 200,
          "result": {
              "user_id": 3,
              "username": "irsyaadbp",
              "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MywiaWF0IjoxNTcxNDQ2MDk3LCJleHAiOjE1NzE0NDk2OTd9.lUn3yz0j0Em5GR3JhLvNyEgkUe2FbgWYUZB1XV4BXk8"
          }
      }
      
  • Get User By Id
    • Request: PUT /user/:user_id
    • Response:
      {
          "status": 200,
          "result": [
              {
                  "id": 3,
                  "username": "adminakjdha",
                  "role": "Manajer",
                  "created_at": "2019-10-20T02:21:27.000Z",
                  "updated_at": "2019-10-20T04:40:43.000Z"
              }
          ]
      }
      
  • Update User By Id
    • Request: PUT /user/:user_id
      {
          "username": "irsyaad101",
          "password": "testPassword1",
          "user_role": "Manager"
      }
      
    • Response:
      {
          "status": 200,
          "result": "Updated user successfully"
      }
      
  • Delete User By Id
    • Request: DELETE /user/:user_id
    • Response:
      {
          "status": 200,
          "result": "Deleted user successfully"
      }
      

CRUD Product Endpoint

  • Get All Product

    • Request : GET /product

    • More Options :

      • Search : add params ?search=
      • Sort By : add params ?sortby=name/category/updated and ?orderby=asc/desc
      • Pagination: add params ?page= to get page of product and ?perpage= to show the max product in one page, if not add the params, default value for page is 1 and perpage is 10
    • Response :

      {
          "status": 200,
          "result": {
              "infoPage": {
                  "page": 1,
                  "totalProduct": 13,
                  "maxPage": 2
              },
              "data": [
                  {
                      "id": 1,
                      "product_name": "Nasi Kucing",
                      "description": "Nasi kucing is an Indonesian rice dish that originated from Yogyakarta, Semarang, and Surakarta but has since spread. It consists of a small portion of rice with toppings, usually sambal, dried fish, and tempeh, wrapped in banana leaves.",
                      "image": "https://upload.wikimedia.org/wikipedia/commons/9/9d/Nasi_kucing_langgi.jpg",
                      "category": "Food",
                      "price": 1500,
                      "quantity": 23,
                      "created_at": "2019-10-18T05:40:32.000Z",
                      "updated_at": "2019-10-18T09:35:43.000Z"
                  },
                  {
                      "id": 2,
                      "product_name": "Bakso",
                      "description": "Bakso or baso is an Indonesian meatball, or a meat paste made from beef surimi. Its texture is similar to the Chinese beef ball, fish ball, or pork ball. The word bakso may refer to a single meatball or the complete dish of meatball soup.",
                      "image": "https://upload.wikimedia.org/wikipedia/commons/2/28/Bakso_mi_bihun.jpg",
                      "category": "Food",
                      "price": 10000,
                      "quantity": 23,
                      "created_at": "2019-10-18T05:41:02.000Z",
                      "updated_at": "2019-10-18T09:35:43.000Z"
                  },
                  {
                      "id": 3,
                      "product_name": "Rendang",
                      "description": "Rendang is an Indonesian spicy red meat dish originating from the Minangkabau people of Indonesia. It has spread across Indonesia to the cuisines of neighbouring Southeast Asian countries.",
                      "image": "https://rasamalaysia.com/wp-content/uploads/2018/04/beef-rendang-thumb.jpg",
                      "category": "Food",
                      "price": 6000,
                      "quantity": 23,
                      "created_at": "2019-10-18T05:41:14.000Z",
                      "updated_at": "2019-10-18T09:35:43.000Z"
                  },
                  {
                      "id": 4,
                      "product_name": "Sayur Asem",
                      "description": "Sayur asem or sayur asam is a Southeast Asian vegetable soup originating from Indonesia. It is a popular Indonesian dish, consisting of vegetables in tamarind soup.",
                      "image": "https://cdn.idntimes.com/content-images/post/20181008/7e14931dd8f60e46c707f79748f54ce1_600x400.jpg",
                      "category": "Food",
                      "price": 8000,
                      "quantity": 25,
                      "created_at": "2019-10-18T05:41:50.000Z",
                      "updated_at": "2019-10-18T09:35:43.000Z"
                  },
                  {
                      "id": 5,
                      "product_name": "Spaghetti",
                      "description": "Spaghetti is a long, thin, solid, cylindrical pasta. Spaghettoni is a thicker form of spaghetti, while capellini is a very thin spaghetti. It is a staple food of traditional Italian cuisine. Like other pasta, spaghetti is made of milled wheat and water and sometimes enriched with vitamins and minerals.",
                      "image": "https://www.inspiredtaste.net/wp-content/uploads/2019/03/Spaghetti-with-Meat-Sauce-Recipe-1-1200.jpg",
                      "category": "Food",
                      "price": 10000,
                      "quantity": 25,
                      "created_at": "2019-10-18T05:42:26.000Z",
                      "updated_at": "2019-10-18T09:35:43.000Z"
                  },
                  {
                      "id": 6,
                      "product_name": "Bulgogi",
                      "description": "Bulgogi, literally "fire meat", is a gui made of thin, marinated slices of beef or pork grilled on a barbecue or on a stove-top griddle. It is also often stir-fried in a pan in home cooking. Sirloin, rib eye or brisket are frequently used cuts of beef for the dish.",
                      "image": "https://assets.bonappetit.com/photos/57acd741f1c801a1038bc801/16:9/w_1200,c_limit/basic-bulgogi.jpg",
                      "category": "Food",
                      "price": 10000,
                      "quantity": 25,
                      "created_at": "2019-10-18T05:44:32.000Z",
                      "updated_at": "2019-10-18T09:35:43.000Z"
                  },
                  {
                      "id": 7,
                      "product_name": "Es Campur",
                      "description": "In Indonesia, es campur is sold from humble traveling trolley to restaurants. For Indonesian Muslims, es campur and kolak are popular treats during Ramadan for iftar, often sold prior to breaking the fast. It is quite similar to es teler and es doger although with different content.",
                      "image": "https://foodizz.id/blog/wp-content/uploads/2019/05/Es-Campur-Tips-dan-Trik-dalam-Membuat-Es-Campur.png",
                      "category": "Drink",
                      "price": 5000,
                      "quantity": 25,
                      "created_at": "2019-10-18T05:45:51.000Z",
                      "updated_at": "2019-10-18T07:09:40.000Z"
                  },
                  {
                      "id": 8,
                      "product_name": "Cendol",
                      "description": "Cendol is an iced sweet dessert that contains droplets of green rice flour jelly, coconut milk and palm sugar syrup. It is commonly found in Southeast Asia and is popular in Indonesia, Malaysia, Brunei, Cambodia, East Timor, Vietnam, Thailand, Singapore, and Burma.",
                      "image": "https://cdn.sindonews.net/dyn/620/content/2018/06/05/185/1311667/es-cendol-bikin-buka-puasa-lebih-nikmat-iyQ.jpg",
                      "category": "Drink",
                      "price": 2500,
                      "quantity": 25,
                      "created_at": "2019-10-18T05:46:35.000Z",
                      "updated_at": "2019-10-18T07:09:40.000Z"
                  },
                  {
                      "id": 9,
                      "product_name": "Ice Cream Sandwich",
                      "description": "An ice cream sandwich is a frozen dessert consisting of ice cream between two biscuits, wafers, or cookies.",
                      "image": "https://www.eatingonadime.com/wp-content/uploads/2018/05/ice-cream-sandwiches-square.jpg",
                      "category": "Drink",
                      "price": 2000,
                      "quantity": 25,
                      "created_at": "2019-10-18T05:47:44.000Z",
                      "updated_at": "2019-10-18T07:09:40.000Z"
                  },
                  {
                      "id": 10,
                      "product_name": "Ice Tea",
                      "description": "Iced tea is a form of cold tea. Though usually served in a glass with ice, it can refer to any tea that has been chilled or cooled. It may be sweetened with sugar, syrup and/or apple slices.",
                      "image": "https://i0.wp.com/member.rumah-kopi.com/wp-content/uploads/2019/05/teh.jpg?fit=700%2C700&ssl=1",
                      "category": "Drink",
                      "price": 2000,
                      "quantity": 25,
                      "created_at": "2019-10-18T05:49:00.000Z",
                      "updated_at": "2019-10-18T07:09:40.000Z"
                  }
              ]
          }
      }
      
  • Get Product By Id

    • Request : GET /product/:prod_id
    • Response :
      {
          "status": 200,
          "result": [
              {
                  "id": 1,
                  "product_name": "Nasi Kucing",
                  "description": "Nasi kucing is an Indonesian rice dish that originated from Yogyakarta, Semarang, and Surakarta but has since spread. It consists of a small portion of rice with toppings, usually sambal, dried fish, and tempeh, wrapped in banana leaves.",
                  "image": "https://upload.wikimedia.org/wikipedia/commons/9/9d/Nasi_kucing_langgi.jpg",
                  "category": "Food",
                  "price": 1500,
                  "quantity": 23,
                  "created_at": "2019-10-18T05:40:32.000Z",
                  "updated_at": "2019-10-18T09:35:43.000Z"
              }
          ]
      }
      
  • Create a Product

    • Request : POST /product
      {
          "prod_name": "Nasi Kucing",
          "prod_desc": "Nasi kucing is an Indonesian rice dish that originated from Yogyakarta, Semarang, and Surakarta but has since spread. It consists of a small portion of rice with toppings, usually sambal, dried fish, and tempeh, wrapped in banana leaves.",
          "prod_image": "https://upload.wikimedia.org/wikipedia/commons/9/9d/Nasi_kucing_langgi.jpg",
          "category_id": 1,
          "price": 10000,
          "quantity": 6
      }
      
      IMPORTANT! If category_id null, category_id have default value 1, cause 1 is Uncategorized if you use my setting database in file database.sql
    • Response :
      {
          "status": 200,
          "result": "Product added sucessfully"
      }
      
  • Update a Product

    • Request : PUT /product/:prod_id
      {
          "prod_name": "Nasi Kucing",
          "prod_desc": "Nasi kucing is an Indonesian rice dish that originated from Yogyakarta, Semarang, and Surakarta but has since spread. It consists of a small portion of rice with toppings, usually sambal, dried fish, and tempeh, wrapped in banana leaves.",
          "prod_image": "https://upload.wikimedia.org/wikipedia/commons/9/9d/Nasi_kucing_langgi.jpg",
          "category_id": 1,
          "price": 10000,
          "quantity": 6
      }
      
    • Response :
      {
          "status": 200,
          "result": "Product updated sucessfully"
      }
      
  • Delete a Product

    • Request : DELETE /prod_id/:prod_id
    • Response :
      {
          "status": 200,
          "result": "Product deleted successfully"
      }
      

CRUD Category Endpoint

  • Read All Category
    • Request : GET /category
    • More Options :
      • Pagination : add params ?page= to get page of product and ?perpage= to show the max product in one page, if not add the params default value for page is 1 and perpage is 10
    • Response :
      {
          "status": 200,
          "result": {
              "infoPage": {
                  "page": 1,
                  "totalProduct": 3,
                  "maxPage": 1
              },
              "result": [
                  {
                      "id": 1,
                      "name": "Uncategorized",
                      "created_at": "2019-10-18T07:12:13.000Z",
                      "updated_at": null
                  },
                  {
                      "id": 2,
                      "name": "Drink",
                      "created_at": "2019-10-18T07:12:20.000Z",
                      "updated_at": "2019-10-18T12:52:19.000Z"
                  },
                  {
                      "id": 3,
                      "name": "Food",
                      "created_at": "2019-10-18T09:34:27.000Z",
                      "updated_at": null
                  }
              ]
          }
      }
      
  • Create a Category
    • Request : POST /category
      {
          "category_name": "Food"
      }
      
    • Response :
      {
          "status": 200,
          "result": "Category added successfully"
      }
      
  • Update a Category
    • Request : PUT /category/:category_id
      {
          "category_name": "Snack"
      }
      
    • Response :
      {
          "status": 200,
          "result": "Category updated successfully"
      }
      
  • Delete a Category
    • Request : DELETE /category/:category_id
    • Response :
      {
          "status": 200,
          "result": "Category deleted successfully"
      }
      

Transaction Order Endpoint

  • Get All Order

    • Request : GET /order
    • More Options :
      • Pagination : add params ?page= to get page of product and ?perpage= to show the max product in one page, if not add the params default value for page is 1 and perpage is 10
    • Response :
      {
          "status": 200,
          "result": {
              "infoPage": {
                  "page": 1,
                  "totalProduct": 3,
                  "maxPage": 1
              },
              "result": [
                  {
                      "id": 1,
                      "admin_id": 1,
                      "order_id": 380699,
                      "total_price": 1000000,
                      "status": "success",
                      "cancel_reason": null,
                      "created_at": "2019-10-18T07:47:51.000Z",
                      "updated_at": null
                  },
                  {
                      "id": 2415,
                      "admin_id": 1,
                      "order_id": 241190,
                      "total_price": 20000000,
                      "status": "success",
                      "cancel_reason": null,
                      "created_at": "2019-10-18T13:11:02.000Z",
                      "updated_at": null
                  },
                  {
                      "id": 2416,
                      "admin_id": 1,
                      "order_id": 132206,
                      "total_price": 20000000,
                      "status": "success",
                      "cancel_reason": null,
                      "created_at": "2019-10-18T13:15:37.000Z",
                      "updated_at": null
                  }
              ]
          }
      }
      
  • Create New Order
    IMPORTANT! When create order, quantity of product is automatically reduce, because we use trigger in mysql

    • Request : POST /order
      {
          "admin_id": 1,
          "total_price": 20000000,
          "detail_order": [
              {"prod_id": 1, "quantity": 3, "sub_total": 20000},
              {"prod_id": 2, "quantity": 3, "sub_total": 30000}
          ]
      }
      
    • Response :
      {
          "status": 200,
          "result": "Order added successfully"
      }
      
  • Update Status Order

    • Request : PUT /order/:order_id
      value of status only success or cancel
      {
          "status": "cancel",
          "cancel_reason": "product defective production"
      }
      
    • Response :
      {
          "status": 200,
          "result": "Order updated to 'cancel'"
      }
      

Support

For API support, please email irsyaadbp01@gmail.com

About

Point of Sales RESTful API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published