Championship backend

Installation

Before run application need to install the latest version of Node.js.

Configuration

First need to change the configuration files for server. Configuration files already into ./config directory. Configuration files are available for each NODE_ENV separately. They also extend from the default.js file.

config
├── default.js
├── development.js
├── production.js
└── staging.js

Documentation: https://github.com/lorenwest/node-config/wiki

ENV

Key Description Default
NODE_ENV Env for run application development
API_PORT Port for application 5000
DB_HOST Host for PostgreSQL server 127.0.0.1
DB_NAME Name for database tt_db
DB_USER User name for PostgreSQL tt_user
DB_PASSWORD Password name for PostgreSQL tt_password

Run

Before run need to install dependencies, migrations and seeds.

npm i
npm run migration
npm run seed

Run with debugger:

npm run dev

Run for staging/production:

npm run start

Routes

GET /countries

Response:

{
    "status": true,
    "result": [
        {
            "id": 1,
            "name": "Russia",
            "created_at": "2019-02-13T07:51:59.732Z",
            "updated_at": "2019-02-13T07:51:59.732Z"
        }
    ]
}

GET /countries/1

Response:

{
    "status": true,
    "result": {
        "country": {
            "id": 1,
            "name": "Russia",
            "created_at": "2019-02-13T07:51:59.732Z",
            "updated_at": "2019-02-13T07:51:59.732Z"
        },
        "teams": [
            {
                "id": 2,
                "name": "CSKA Moscow",
                "created_at": "2019-02-13T07:51:59.739Z",
                "updated_at": "2019-02-13T07:51:59.739Z"
            }
        ]
    }
}

POST /countries/create

Country Creation Method.

Payload description:

Key Description Is Required?
name Name of country yes

Request:

curl -X POST \
  http://localhost:5000/countries/create \
  -H 'Content-Type: application/json' \
  -d '{"name": "Turkey"}'

Response (success):

{
    "status": true
}

Response (error):

{
    "status": false,
    "error": "validation error child \"name\" fails because [\"name\" is required]"
}

PUT /countries/update

Country Update Method.

Payload description:

Key Description Is Required?
id Item ID yes
name Name of country yes

Request:

curl -X PUT \
  http://localhost:5000/counntries/update \
  -H 'Content-Type: application/json' \
  -d '{"id": 9, "name": "Egypt"}'

Response (success):

{
    "status": true
}

Response (error):

{
    "status": false,
    "error": "validation error child \"id\" fails because [\"id\" is required]. child \"name\" fails because [\"name\" is required]"
}

DELETE /countries/delete

Country Delete Method.

Payload description:

Key Description Is Required?
id Item ID yes

Request:

curl -X DELETE \
  http://localhost:5000/teams/delete \
  -H 'Content-Type: application/json' \
  -d '{"id": 3}'

Response (success):

{
    "status": true
}

Response (error):

{
    "status": false,
    "error": "validation error child \"id\" fails because [\"id\" is required]"
}

GET /teams

Response:

{
    "status": true,
    "result": [
        {
            "id": 1,
            "country": "Russia",
            "country_id": 1,
            "name": "Spartak Moscow",
            "created_at": "2019-02-13T07:51:59.739Z",
            "updated_at": "2019-02-13T07:51:59.739Z"
        },
    ]
}

GET /teams/1

Response:

{
    "status": true,
    "result": {
        "id": 1,
        "country": "Russia",
        "country_id": 1,
        "name": "Spartak Moscow",
        "created_at": "2019-02-13T07:51:59.739Z",
        "updated_at": "2019-02-13T07:51:59.739Z"
    }
}

POST /teams/create

Team Creation Method.

Payload description:

Key Description Is Required?
name Name of team yes
country Country ID yes

Request:

curl -X POST \
  http://localhost:5000/teams/create \
  -H 'Content-Type: application/json' \
  -d '{"name": "FC Bishkek", "country": 3}'

Response (success):

{
    "status": true
}

Response (error):

{
    "status": false,
    "error": "validation error child \"country\" fails because [\"country\" is required]. child \"name\" fails because [\"name\" is required]"
}

PUT /teams/update

Teams Update Method.

Payload description:

Key Description Is Required?
id Item ID yes
name Name of country yes
country Country ID yes

Request:

curl -X PUT \
  http://localhost:5000/teams/update \
  -H 'Content-Type: application/json' \
  -d '{"name": "FC Egypt", "id": 9, "country": 3}'

Response (success):

{
    "status": true
}

Response (error):

{
    "status": false,
    "error": "validation error child \"id\" fails because [\"id\" is required]. child \"name\" fails because [\"name\" is required]"
}

DELETE /teams/delete

Teams Delete Method.

Payload description:

Key Description Is Required?
id Item ID yes

Request:

curl -X DELETE \
  http://localhost:5000/teams/delete \
  -H 'Content-Type: application/json' \
  -d '{"id": 3}'

Response (success):

{
    "status": true
}

Response (error):

{
    "status": false,
    "error": "validation error child \"id\" fails because [\"id\" is required]"
}