Skip to content

Project built during Rocketseat's Next Level Week #3

License

Notifications You must be signed in to change notification settings

DiegoVictor/happy-api

Repository files navigation

[API] Happy

CircleCI typescript sqlite3 eslint airbnb-style jest coverage MIT License PRs Welcome
Run in Insomnia}

Responsible for provide data to the web and mobile front-ends. Permit to register orphanages. The app has validation, also a simple versioning was made.

Table of Contents

Installing

Easy peasy lemon squeezy:

$ yarn

Or:

$ npm install

Was installed and configured the eslint and prettier to keep the code clean and patterned.

Configuring

The application use just one database: SQLite. For the fastest setup is recommended to use docker-compose, you just need to up all services:

$ docker-compose up -d

SQLite

Store the orphanages. For more information to how to setup your database see:

You can find the application's ormconfig.json file in the root folder.

Migrations

Remember to run the database migrations:

$ yarn ts-node-dev ./node_modules/typeorm/cli.js migration:run -- -d ./src/database/datasource.ts

Or:

$ yarn typeorm migration:run -- -d ./src/database/datasource.ts

See more information on TypeORM Migrations.

.env

In this file you may configure your app's port and a url. Rename the .env.example in the root directory to .env then just update with your settings.

key description default
APP_PORT Port number where the app will run. 3333
BASE_URL App's url. http://localhost:3333

Usage

To start up the app run:

$ yarn dev:server

Or:

npm run dev:server

Versioning

A simple versioning was made. Just remember to set after the host the /v1/ string to your requests.

GET http://localhost:3333/v1/orphanages

Routes

route HTTP Method params description
/orphanages GET - Lists orphanages.
/orphanages/:id GET :id of the orphanage. Return one orphanage.
/orphanages POST Body with new orphanage form data (See insomnia file for good example). Create a new orphanage.

Requests

  • POST /orphanages

Request body:

{
  "name": "Hackett, Becker and Fadel",
  "latitude": -85.8713,
  "longitude": -73.3957,
  "about": "Adipisci cupiditate illo rerum sunt tempore. Non voluptate laborum enim hic tenetur perspiciatis sint. Quo totam recusandae dolores et ullam commodi. Ut consectetur saepe id voluptatem et quidem. Dolor neque consequuntur ipsa. Placeat sit aut nostrum similique dolorem voluptatem et velit enim.",
  "instructions": "Venha visitar",
  "opening_hours": "Das 8h às 18h",
  "open_on_weekends": true,
  "images": <file(s)>
}

Running the tests

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

$ yarn test

Or:

$ npm run test

Coverage report

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