{"id":17651743,"url":"https://github.com/diegovictor/npser","last_synced_at":"2025-05-07T01:43:29.415Z","repository":{"id":98964689,"uuid":"341695032","full_name":"DiegoVictor/NPSer","owner":"DiegoVictor","description":"Project built during Rocketseat's Next Level Week #4","archived":false,"fork":false,"pushed_at":"2025-03-24T02:22:06.000Z","size":1206,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T05:03:35.410Z","etag":null,"topics":["api","coverage-report","editorconfig","eslint","insomnia","nextlevelweek","nextlevelweek-booster","nlw","node","nodejs","npser","prettier","rocketseat","sqlite","ts","typeorm","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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}},"created_at":"2021-02-23T21:28:10.000Z","updated_at":"2025-03-24T02:22:10.000Z","dependencies_parsed_at":"2024-06-29T16:29:38.253Z","dependency_job_id":"7f67667a-fba2-45e7-b6e9-ccdab593cd5c","html_url":"https://github.com/DiegoVictor/NPSer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2FNPSer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2FNPSer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2FNPSer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2FNPSer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DiegoVictor","download_url":"https://codeload.github.com/DiegoVictor/NPSer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252798510,"owners_count":21805876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","coverage-report","editorconfig","eslint","insomnia","nextlevelweek","nextlevelweek-booster","nlw","node","nodejs","npser","prettier","rocketseat","sqlite","ts","typeorm","typescript"],"created_at":"2024-10-23T11:43:28.181Z","updated_at":"2025-05-07T01:43:29.396Z","avatar_url":"https://github.com/DiegoVictor.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NPSer\n[![AppVeyor](https://img.shields.io/appveyor/build/diegovictor/npser?logo=appveyor\u0026style=flat-square)](https://ci.appveyor.com/project/DiegoVictor/npser)\n[![sqlite3](https://img.shields.io/badge/sqlite-5.1.7-003b57?style=flat-square\u0026logo=sqlite\u0026logoColor=white)](https://www.sqlite.org)\n[![typescript](https://img.shields.io/badge/typescript-5.5.4-3178c6?style=flat-square\u0026logo=typescript)](https://www.typescriptlang.org/)\n[![eslint](https://img.shields.io/badge/eslint-8.57.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/npser?logo=codecov\u0026style=flat-square)](https://codecov.io/gh/DiegoVictor/npser)\n[![MIT License](https://img.shields.io/badge/license-MIT-green?style=flat-square)](https://raw.githubusercontent.com/DiegoVictor/NPSer/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=NPSer\u0026uri=https%3A%2F%2Fraw.githubusercontent.com%2FDiegoVictor%2FNPSer%2Fmain%2FInsomnia_2024-06-23.json)\n\n## Table of Contents\n* [Installing](#installing)\n  * [Configuring](#configuring)\n    * [SQLite](#sqlite)\n      * [Migrations](#migrations)\n    * [.env](#env)\n* [Usage](#usage)\n  * [Error Handling](#error-handling)\n    * [Errors Reference](#errors-reference)\n  * [Versioning](#versioning)\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: [SQLite](https://www.sqlite.org/index.html). 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### SQLite\nStore all users and surveys. For more information to how to setup your database see:\n* [typeorm](https://typeorm.io/#/using-ormconfig)\n\u003e You can find the application's `ormconfig.json` file in the root folder.\n\n#### Migrations\nRemember to run the database migrations:\n```\n$ yarn ts-node-dev ./node_modules/typeorm/cli.js migration:run -- -d ./src/database/datasource.ts\n```\nOr:\n```\n$ yarn typeorm migration:run -- -d ./src/database/datasource.ts\n```\n\u003e See more information on [TypeORM Migrations](https://typeorm.io/#/migrations).\n\n### .env\nIn this file you may configure app's port and a url to documentation (this will be returned with error responses, see [error section](#error-handling)). Rename the `.env.example` in the root directory to `.env` then just update with your settings.\n\n|key|description|default\n|---|---|---\n|URL_MAIL|Url to send the NPS answer|`http://localhost:3333/answers`\n|PORT|Port number where the app will run.|`3333`\n|DOCS_URL|An url to docs where users can find more information about the app's internal code errors.|`https://github.com/DiegoVictor/npser#errors-reference`\n\n# Usage\nTo start up the app run:\n```\n$ yarn dev:server\n```\nOr:\n```\nnpm run dev:server\n```\n\n## Error Handling\nInstead of only throw a simple message and HTTP Status Code this API return friendly errors:\n```json\n{\n  \"statusCode\": 400,\n  \"error\": \"Bad Request\",\n  \"message\": \"User already exists\",\n  \"code\": 140,\n  \"docs\": \"https://github.com/DiegoVictor/npser#errors-reference\"\n}\n```\n\u003e Errors are implemented with [@hapi/boom](https://github.com/hapijs/boom).\n\u003e As you can see a url to error docs are returned too. To configure this url update the `DOCS_URL` key from `.env` file.\n\u003e In the next sub section ([Errors Reference](#errors-reference)) you can see the errors `code` description.\n\n### Errors Reference\n|code|message|description\n|---|---|---\n|140|User already exists|The provided email is already registered by another user.\n|240|User does not exists|The provided email was not found.\n|241|Survey does not exists|The provided survey id does not references an existing registry in the database.\n|242|Answer not found|A survey was not sent to this user.\n\n## Versioning\nA simple versioning was made. Just remember to set after the `host` the `/v1/` string to your requests.\n```\nGET http://localhost:3333/v1/surveys\n```\n\n## Routes\n|route|HTTP Method|params|description\n|:---|:---:|:---:|:---:\n|`/users`|POST|Body with user `name` and `email`.|Create a new user\n|`/surveys`|GET|`page` query parameter.|Lists surveys.\n|`/surveys`|POST|Body with user `title` and `description`.|Create a new survey\n|`/send_mail`|POST|Body with user `email` and a `survey_id`.|Send the NPS to provided user\n|`/answers`|GET|`page` query parameter.|List surveys' answers\n|`/answers/:value`|GET|survey `value` url parameter and survey user `id` query parameter.|Set user's avaliation to one survey\n|`/nps/:survey_id`|GET|`survey_id` url parameter.|Show survey NPS\n\n### Requests\n* `POST /users`\n\nRequest body:\n```json\n{\n  \"name\": \"John Doe\",\n  \"email\": \"johndoe@example.com\"\n}\n```\n\n* `POST /survey`\n\nRequest body:\n```json\n{\n  \"title\": \"Internal Directives Engineer\",\n  \"description\": \"Cupiditate modi occaecati aut?\"\n}\n```\n\n* `POST /send_mail`\n\nRequest body:\n```json\n{\n  \"email\": \"johndoe@example.com\",\n  \"survey_id\": \"388017f8-dfdf-4681-9112-e1bb0de009ec\"\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%2Fnpser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiegovictor%2Fnpser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegovictor%2Fnpser/lists"}