/SOS_PET_API

Node backend API with typescript and express, serving the front-end of the social network sos_pet

Primary LanguageTypeScript

SOS_PET_API

Run in Insomnia}

status: 🚧 SOS_PET_API 🚀 developing... 🚧

Node backend API with typescript and express, serving the front-end of the social network sos_pet (front repository: https://github.com/erikaperciliano/SOS-PET-new-version-).

Features

  • Allows users to register
  • Token route authentication
  • List all users

Table of Contents

Prerequisites

Before starting, you will need to have the following tools installed on your machine:

Besides, it's good to have an editor to work with the code like: VSCode

Setting Database

Create database on postgres:

  • sos_pet
  • sos_pet_test

Starting Project

# Clone this repository
$ git clone https://github.com/WallaceMachado/SOS_PET_API.git

# Access the project folder in the terminal/cmd
$ cd SOS_PET_API

# Install dependencies
$ npm install

or

$ yarn

# Make changes to the database connection data in the ormconfig.json file
$ yarn typeorm migration:run

# Server is running:3333 - acesse <http://localhost:3333>

Routes

Route HTTP Method Params Description Auth Method
/users POST Body with user's name, email, password, username and user_type Created user
/users GET - Retrieve a list of users. Bearer
/users/profile GET - Return user's profile. Bearer
/users/avatar PATCH Multipart payload with a atavar field with a image (See insomnia file for good example). Update user avatar. Bearer
/sessions POST Body with user's email and password. Authenticates user, return a Bearer Token and user's name, email
/animals POST Body with user's type_animal, name, animal_gender, breed, description, state, city, age Created Animal Bearer

Routes with Bearer as auth method expect an Authorization header. See Bearer Token section for more information.

Bearer Token

A few routes expect a Bearer Token in an Authorization header.

You can see these routes in the routes section.

GET http://localhost:3333/v1/rentals Authorization: Bearer <token>

To achieve this token you just need authenticate through the /sessions route and it will return the token key with a valid Bearer Token

Running the tests

Jest was the choice to test the app, to run:

$ yarn test

Coverage report

You can see the coverage report inside tests/coverage. They are automatically created after the tests run.

Autor

Feito com ❤️ por Wallace Machado 🚀🏽 Entre em contato!