An open API service indexing awesome lists of open source software.

https://github.com/or-abdillh/stock-api

Backend service for Stock App using NodeJS , ExpressJS, and MySQL
https://github.com/or-abdillh/stock-api

api expressjs inventory inventory-management nodejs nodejs-server rest-api restful-api

Last synced: 12 months ago
JSON representation

Backend service for Stock App using NodeJS , ExpressJS, and MySQL

Awesome Lists containing this project

README

          

Stock API


Aplication Backend For Stock App

### About
This application is used to serve data requests from the Stock-App client application to the server.
Built with Node JS, Express JS and MySql

### Dependencies
- body parser v.1.19.0
- cors v.2.8.5
- express v.4.17.1
- express fileupload v.1.2.1
- md5 v.2.3.0
- mysql v.2.18.1
- random token v.0.0.8
- nodemon 2.0.13

### How to start
- Use this command for cloning this repository git clone https://github.com/or-abdillh/stock-api.git
- Then, use this command cd stock-api
- Install all dependencies npm install

### Running The Server
- Make sure you have exported the database using this file ./DB/stockAppDB.sql
- Running the mysql services if you use mysql CLI with this command mysqld_safe
- Before running the server you must setup the configuration connection to your mysql in ./connection/conn.js
- Then, use this command to run server npm start
- By default the server running on PORT 8080, you can change the PORT in ./server.js

### Hostname & Endpoint API
- HOSTNAME : http://localhost:8080/

##### endpoint
- /

purpose : Testing response from server

- /auth

purpose : login validation

request method POST

- /token

purpose : Token validation

request method POST

- /logout

purpose : Remove TOKEN and create new TOKEN to table User

request method GET

- /profile

purpose : Get fullname, amounts of category and products user have

request method GET

- /products

purpose : Get all products from table Products

request method GET

- /upload

purpose : Upload image to server, path uploaded file /public

request method POST

- /createProduct

purpose : Create new product

request method POST

- /removeFile

purpose : Remove file image from server

request method DELETE

- /deleteProduct

purpose : remove product from table Products

request method DELETE

- /updateProduct

purpose : update product from table Products

request method POST

- /categorys

purpose : Get all categorys from table Categorys

request method GET

- /createCategory

purpose : Create new category

request method POST

- /deleteCategory

purpose : Remove category from table Categorys

request method DELETE

- /setUncategorys

purpose : Set name category product to uncategorys after the current category has deleted

request method POST

- /updateCategory

purpose : Update the category from table Categorys

request method POST

- /search/:keyword/:category

purpose : Get products by keyword and category product

request method GET

- /changeName

purpose : Update name user

request method POST

- /changePassword

purpose : Change password user

request method POST

### Example request
Every time you make a request there must be a token in the request header as an identifier

```javascript
import BASE_URL from '../BASE_URL.js'

//Create Headers to save the token
const headers = {
headers: {
token: 'Get the token from auth endpoint'
}
}

axios.get(`${BASE_URL}/products`, headers)
.then(res => {
console.log(res.data)
})
.catch(err => {
console.error(err)
})
```

### Example response
- from /auth
```json
{
"status": 200,
"message": "success",
"results": {
"TOKEN": "7yyxswvcj6ivjp8c0p6tqult94nx3kbjgetb9tpzfs0tug3f9d4cjsdd9f86otohoa7gc369ukyadztalgjbq20vjxwqeno3dp4z"
}
}
```

- from /profile
```json
{
"status": 200,
"message": "success",
"results": {
"fullname": "Sandhika Galih",
"products": "45"
"categorys": "5"
}
}
```
- from /products
```json
{
"status": 200,
"message": "success",
"results": [
{
"id_product": 76,
"name_product": "Happy Cuan Figma UI Kits",
"price_product": 567000,
"stock_product": 2,
"image_product": "http://localhost:8080/public/product-1635568922040.jpg",
"category_product": "UI",
"last_modified": 1635585093337,
"stock_unit": "pcs"
}
]
}
```
### Thanks
- Support me with a cup of coffee and other snacks [here ..](https://saweria.co/orabdillh)
- Don't forget to give me star in this repository 🙏🏻🙏🏻
- See my other projects on instagram [@or_abdillh](http://www.instagram.com/or_abdillh)

[Oka R Abdillah ](http://github.com/or-abdillh)

Last edited on : 31/10/2021