{"id":17651753,"url":"https://github.com/diegovictor/central-de-herois-api","last_synced_at":"2026-04-13T13:32:02.453Z","repository":{"id":211095446,"uuid":"726455808","full_name":"DiegoVictor/central-de-herois-api","owner":"DiegoVictor","description":"City's Hero Manager, try keep the city safe! ","archived":false,"fork":false,"pushed_at":"2025-07-11T12:17:39.000Z","size":708,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-11T15:06:32.145Z","etag":null,"topics":["api","backend","central-de-herois","eslint","heroes","javascript","js","node","nodejs","prettier"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DiegoVictor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-12-02T13:02:26.000Z","updated_at":"2025-07-11T12:17:42.000Z","dependencies_parsed_at":"2023-12-24T16:25:42.904Z","dependency_job_id":"7cb8d778-191a-43c4-afa7-67222c045643","html_url":"https://github.com/DiegoVictor/central-de-herois-api","commit_stats":null,"previous_names":["diegovictor/central-de-herois-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DiegoVictor/central-de-herois-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fcentral-de-herois-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fcentral-de-herois-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fcentral-de-herois-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fcentral-de-herois-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DiegoVictor","download_url":"https://codeload.github.com/DiegoVictor/central-de-herois-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fcentral-de-herois-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31754856,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T13:27:56.013Z","status":"ssl_error","status_checked_at":"2026-04-13T13:21:23.512Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","backend","central-de-herois","eslint","heroes","javascript","js","node","nodejs","prettier"],"created_at":"2024-10-23T11:43:29.734Z","updated_at":"2026-04-13T13:32:02.444Z","avatar_url":"https://github.com/DiegoVictor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [API] Central de Heróis\n[![AppVeyor](https://img.shields.io/appveyor/build/diegovictor/central-de-herois-api?logo=appveyor\u0026style=flat-square)](https://ci.appveyor.com/project/DiegoVictor/central-de-herois-api)\n[![mongodb](https://img.shields.io/badge/mongodb-5.9.2-13aa52?style=flat-square\u0026logo=mongodb\u0026logoColor=white)](https://mongodb.com/)\n[![eslint](https://img.shields.io/badge/eslint-8.55.0-4b32c3?style=flat-square\u0026logo=eslint)](https://eslint.org/)\n[![airbnb-style](https://flat.badgen.net/badge/style-guide/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript)\n[![jest](https://img.shields.io/badge/jest-29.7.0-brightgreen?style=flat-square\u0026logo=jest)](https://jestjs.io/)\n[![coverage](https://img.shields.io/codecov/c/gh/DiegoVictor/central-de-herois-api?logo=codecov\u0026style=flat-square)](https://codecov.io/gh/DiegoVictor/central-de-herois-api)\n[![MIT License](https://img.shields.io/badge/license-MIT-green?style=flat-square)](https://raw.githubusercontent.com/DiegoVictor/central-de-herois-api/main/LICENSE)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\u003cbr\u003e\n[![Run in Insomnia}](https://insomnia.rest/images/run.svg)](https://insomnia.rest/run/?label=Central%20de%20Her%C3%B3is\u0026uri=https%3A%2F%2Fraw.githubusercontent.com%2FDiegoVictor%2Fcentral-de-herois-api%2Fmain%2FInsomnia_2024-11-28.json)\n\nAllow users to register and log in, to create, update and delete heroes, list monsters and change a combat status, it also receive monsters occurrences and try to allocate heroes to fight with the monster. The app uses JWT for authentication.\n\n## Table of Contents\n* [Installing](#installing)\n  * [Configuring](#configuring)\n    * [.env](#env)\n    * [MongoDB](#mongodb)\n* [Usage](#usage)\n  * [Scripts](#scripts)\n  * [Bearer Token](#bearer-token)\n  * [Routes](#routes)\n    * [Requests](#requests)\n* [Running the tests](#running-the-tests)\n  * [Coverage report](#coverage-report)\n\n# Installing\nEasy peasy lemon squeezy:\n```\n$ yarn\n```\nOr:\n```\n$ npm install\n```\n\u003e Was installed and configured the [`eslint`](https://eslint.org/) and [`prettier`](https://prettier.io/) to keep the code clean and patterned.\n\n## Configuring\nThe application use just one database: [MongoDB](https://www.mongodb.com/). For the fastest setup is recommended to use [docker-compose](https://docs.docker.com/compose/), you just need to up all services:\n```\n$ docker-compose up -d\n```\n\n# .env\nIn this file you may configure your MongoDB's database connection, JWT settings and app's port. Rename the `.env.example` in the root directory to `.env` then just update with your settings.\n\n|key|description|default\n|---|---|---\n|APP_PORT|Port number where the app will run.|`3333`\n|JWT_SECRET|A alphanumeric random string. Used to create signed tokens.| -\n|JWT_EXPIRATION_TIME|How long time will be the token valid. See [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken#usage) repo for more information.|`7d`\n|MONGO_URL|MongoDB's server url.|`mongodb://mongo:27017/central-de-herois-mongo`\n|MONSTER_WEBSOCKET|Socket's server url|`http://localhost:3000/central-de-herois`\n\n## MongoDB\nStore heroes, monsters and the users utilized by the application. If for any reason you would like to create a MongoDB container instead of use `docker-compose`, you can do it by running the following command:\n```\n$ docker run --name central-de-herois-mongo -d -p 27017:27017 -d mongo\n```\n\n# Usage\nTo start up the app run:\n```\n$ yarn dev:server\n```\nOr:\n```\nnpm run dev:server\n```\n\n## Scripts\nThe application is shipped with a script to run a websocket server and emit monsters occurrences randomly. Run it by:\n```shell\n$ node ./scripts/websocket.js\n```\n\n## Bearer Token\nSome routes expect a Bearer Token in an `Authorization` header.\n\u003e You can see these routes in the [routes](#routes) section.\n```\nGET http://localhost:3333/heroes Authorization: Bearer \u003ctoken\u003e\n```\n\u003e To get this token you just need authenticate through the `/sessions` route and it will return the `token` key with a valid Bearer Token.\n\n## Routes\n|route|HTTP Method|params|description|auth method\n|:---|:---:|:---:|:---:|:---:\n|`/users`|POST|Body with user `name`, `email` and `password`.|Create new user.|:x:\n|`/sessions`|POST|Body with user `email` and `password`.|Authenticates user and return a Bearer Token.|:x:\n|`/heroes`|GET| - |Return all heroes.|Bearer\n|`/heroes`|POST|Body with hero `name`, `latitude`, `longitude`, `rank`, `status`  and `description`|Create a new hero.|Bearer\n|`/heroes/:id`|PUT|Path param with hero `id`. Body with hero `name`, `latitude`, `longitude`, `rank`, `status`  and `description`|Update an existing hero.|Bearer\n|`/heroes/:id`|DELETE|Path param with hero `id`.|Delete an existing hero.|Bearer\n|`/monsters`|GET|Query param with an optional monster `status`.|Return all monsters optionally filtered by status.|Bearer\n|`/monsters/:id/defeated`|PUT|Path param with monster `id`. Body with an array of heroes with `id` and `status` (after the combat finished).|Update monster and hero(es) status.|Bearer\n\n### Requests\n* `POST /users`\n\nRequest body:\n```json\n{\n  \"name\": \"John Doe\",\n  \"email\": \"johndoe@example.com\",\n  \"password\": \"123456\"\n}\n```\n\n* `POST /sessions`\n\nRequest body:\n```json\n{\n  \"email\": \"johndoe@example.com\",\n  \"password\": \"123456\"\n}\n```\n\n* `POST /heroes`\n\nRequest body:\n```json\n{\n  \"name\": \"Saitama\",\n  \"latitude\": \"79.1721\",\n  \"longitude\": \"43.0377\",\n  \"rank\": \"A\",\n  \"status\": \"patrolling\",\n  \"description\": \"The most powerful, but not recognized hero\",\n}\n```\n\n* `PUT /heroes/:id`\n\nRequest body:\n```json\n{\n  \"name\": \"Saitama\",\n  \"latitude\": \"79.1721\",\n  \"longitude\": \"43.0377\",\n  \"rank\": \"A\",\n  \"status\": \"patrolling\",\n  \"description\": \"The most powerful, but not recognized hero\",\n}\n```\n\n* `PUT /monsters/:id/defeated`\n\nRequest body:\n```json\n{\n  \"heroes\": [\n    {\n      \"_id\": \"3f7d0f46-9349-4e20-bcea-80b7e9fdd839\",\n      \"status\": \"out_of_combat\"\n    },\n    {\n      \"_id\": \"83916f30-59e1-4a57-abb0-396d921169e5\",\n      \"status\": \"resting\"\n    }\n  ]\n}\n```\n\n# Running the tests\n[Jest](https://jestjs.io/) was the choice to test the app, to run:\n```\n$ yarn test\n```\nOr:\n```\n$ npm run test\n```\n\n## Coverage report\nYou can see the coverage report inside `tests/coverage`. They are automatically created after the tests run.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegovictor%2Fcentral-de-herois-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiegovictor%2Fcentral-de-herois-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegovictor%2Fcentral-de-herois-api/lists"}