CarlosJSL / ZSSN

API REST developed using nodejs, express , sequelize and postgres

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZSSN (Zombie Survival Social Network) - Back-end

A REST API to store informations about the survivors.

Features

  • Register survivor
  • Update survivor location
  • All Reports
  • Flag survivor as infected

Folder structure

.
├── config
│		└── config.js
│		└── datasource.js
├── controllers
│   ├── itens.js
│   ├── person.js 
│   ├── person_itens.js 
├── models
│   ├── itens.js
│   ├── person.js 
│   ├── person_itens.js 
├── routes
│		└── person.js
├── tests
├── app.js
└── index.js
└── package.json

Tech

  • ES6
  • NodeJS
  • Express
  • Sequelize
  • PostgreSQL

Api Reference

Go to folder /doc and access the index.html file for more informations

Survivor

METODO ENDPOINT FUNCTION
GET /api/person List all persons
GET /api/person/:id List one person by id
GET /api/:id /person/ List one person with it's items
POST /api/person Create a new survivor
POST /api/person/:id/report Informs that survivor is infected
PATCH /api/person/:id Update a survivor

Reports

METODO ENDPOINT FUNCTION
GET /api/report/person/infected Informs the average of infected people
GET /api/report/person/healthy_people Informs the average of non-infected people
GET /api/report/person/average_person_inventory Informs the average of the quantity of items per person
GET /api/report/infected_points Informs the total points lost in items that belong to infected people

Heroku

You can see the API on Heroku. [Heroku Demo] (https://zssn-back-end.herokuapp.com/api/person)

Database

The project needs a relational database because of the relationship rules it needs. The image below shows these relationships

## Running locally

First of all you'll postgresql installed

> sudo apt-get update
> sudo apt-get install postgresql

Download NodeJs

> sudo apt-get update
> sudo apt-get install nodejs

Clone the project

> git clone https://gitlab.com/carlosjsl95/survivorProject.git

Install the project dependencies

> npm i

Then create a database named survivor on postgres and change the options in the file config.js for your password and user

export default{
  database: 'survivor',
  username: 'postgres', <<<< here
  password: 'postgres', <<<< here
  params: {
    dialect: 'postgres',
    define: {
      underscored: true,
    },
  },
};

And finally run it locally

> npm start

Then access http://localhost:7000/{endpoint_name};

Tests

You can run tests with the following commands

> npm test-integration
> npm test-unit

TODO

  • Implement trade's endpoint

About

API REST developed using nodejs, express , sequelize and postgres


Languages

Language:JavaScript 100.0%