davidgonzalezfx / node-express-sequelize

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SuperdFüds warehouse API (CRUD)

📖 Description

API built in nodejs, express and sequelize that allows CRUD operations for warehouses system.


🔧 Install

You have to install all dependencies before execute API:

cd warehouses-api/
npm install
npm run start

📦 Usage

This API allows you to execute CRUD (create, read, update and delete) operations over mysql database that contains warehouse and warehouse_description tables:

  1. Get all warehouses: (GET /api/warehouses)
curl 127.0.0.1:3000/api/warehouses

{
    "status": "4 warehouses fetched",
    "warehouses": [
        {
            "id": 6,
            "name": "Cofradia",
            "headquarters_number": 130000,
            "created_at": "2020-08-31T02:32:07.000Z",
            "updated_at": "2020-08-31T02:32:07.000Z",
            "description": [
                {
                    "id": 5,
                    "warehouse_id": 6,
                    "phone": 3000000,
                    "city": "Bogota",
                    "address": "Cra 1 #1-1",
                    "created_at": "2020-08-31T02:32:07.000Z",
                    "updated_at": "2020-08-31T02:32:07.000Z"
                }
            ]
        }
        
    ]
}
  1. Get one warehouse by id: (GET /api/warehouse/:id)
curl 127.0.0.1:3000/api/warehouse/6

{
    "status": "warehouse #6 fetched",
    "warehouse": {
        "id": 6,
        "name": "wareHouse",
        "headquarters_number": 130000,
        "created_at": "2020-08-31T02:32:07.000Z",
        "updated_at": "2020-08-31T02:32:07.000Z",
        "description": [
            {
                "id": 5,
                "warehouse_id": 6,
                "phone": 3000000,
                "city": "Bogota",
                "address": "Cra 1 #1-1",
                "created_at": "2020-08-31T02:32:07.000Z",
                "updated_at": "2020-08-31T02:32:07.000Z"
            }
        ]
    }
}
  1. Create a new warehouse: (POST /api/warehouses)
curl -d '{"name": "San Diego","headquartersNumber": 130000,"description":[{"phone": 3000000,"city": "Medellin","address": "Cra 2 #2-2"}]}' -H "Content-Type: application/json" -X POST http://127.0.0.1:3000/api/warehouses

{
    "status": "new warehouse created",
    "warehouse": {
        "created_at": "2020-08-31T03:01:58.972Z",
        "updated_at": "2020-08-31T03:01:58.972Z",
        "id": 15,
        "name": "San Diego",
        "headquarters_number": 130000,
        "description": [
            {
                "created_at": "2020-08-31T03:01:58.972Z",
                "updated_at": "2020-08-31T03:01:58.972Z",
                "id": 15,
                "phone": 3000000,
                "city": "Medellin",
                "address": "Cra 2 #2-2",
                "warehouse_id": 15
            }
        ]
    }
}
  1. Update warehouse by id: (PUT /api/warehouse/:id)
curl -d '{"name": "San Carlos"}' -H "Content-Type: application/json" -X PUT http://127.0.0.1:3000/api/warehouse/15

{
    "status": "Instance #15 updated",
    "warehouse": {
        "id": 15,
        "name": "San Carlos",
        "headquarters_number": 130000,
        "created_at": "2020-08-31T03:01:58.000Z",
        "updated_at": "2020-08-31T03:01:58.000Z",
        "description": [
            {
                "id": 15,
                "warehouse_id": 15,
                "phone": 3000000,
                "city": "Medellin",
                "address": "Cra 2 #2-2",
                "created_at": "2020-08-31T03:01:58.000Z",
                "updated_at": "2020-08-31T03:01:58.000Z"
            }
        ]
    }
}
  1. Delete warehouse by id: (DELETe /api/warehouse/:id)
curl -X DELETE http://127.0.0.1:3000/api/warehouse/15

{
    "status": "Total deleted instances: 1"
}

curl 192.168.1.57:3000/api/warehouse/15

{
    "status": "Error while retrieving information from database",
    "error": "Instance not found"
}

Demo: api_demo

⚙️ Tests

To run all tests execute:

npm run test

test


Author

About


Languages

Language:JavaScript 100.0%