{"id":17651772,"url":"https://github.com/diegovictor/deliveryman","last_synced_at":"2025-09-07T17:39:17.760Z","repository":{"id":98963938,"uuid":"441002523","full_name":"DiegoVictor/deliveryman","owner":"DiegoVictor","description":"Application built during the Rocketseat Ignite Bootcamp ","archived":false,"fork":false,"pushed_at":"2025-02-04T22:28:25.000Z","size":1136,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-07T07:15:07.282Z","etag":null,"topics":["api","deliveryman","editorconfig","eslint","ignite","jest","node","nodejs","postgres","rocketseat","ts","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-12-22T22:47:39.000Z","updated_at":"2025-02-04T22:28:29.000Z","dependencies_parsed_at":"2024-01-12T16:52:05.777Z","dependency_job_id":"d5a7392d-b874-4910-b4cd-a565f7aa855d","html_url":"https://github.com/DiegoVictor/deliveryman","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%2Fdeliveryman","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fdeliveryman/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fdeliveryman/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fdeliveryman/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DiegoVictor","download_url":"https://codeload.github.com/DiegoVictor/deliveryman/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252831270,"owners_count":21810784,"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","deliveryman","editorconfig","eslint","ignite","jest","node","nodejs","postgres","rocketseat","ts","typescript"],"created_at":"2024-10-23T11:43:36.237Z","updated_at":"2025-09-07T17:39:17.746Z","avatar_url":"https://github.com/DiegoVictor.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Deliveryman\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/DiegoVictor/deliveryman/config.yml?logo=github\u0026style=flat-square)](https://github.com/DiegoVictor/deliveryman/actions)\n[![postgres](https://img.shields.io/badge/postgres-326690?style=flat-square\u0026logo=postgresql\u0026logoColor=white)](https://www.postgresql.org/)\n[![typescript](https://img.shields.io/badge/typescript-4.5.5-3178c6?style=flat-square\u0026logo=typescript)](https://www.typescriptlang.org/)\n[![prisma](https://img.shields.io/badge/prisma-5.22.0-326690?style=flat-square\u0026logo=prisma\u0026logoColor=white)](https://www.prisma.io/)\n[![eslint](https://img.shields.io/badge/eslint-8.9.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-27.5.1-brightgreen?style=flat-square\u0026logo=jest)](https://jestjs.io/)\n[![coverage](https://img.shields.io/codecov/c/gh/DiegoVictor/deliveryman?logo=codecov\u0026style=flat-square)](https://codecov.io/gh/DiegoVictor/deliveryman)\n[![MIT License](https://img.shields.io/badge/license-MIT-green?style=flat-square)](https://raw.githubusercontent.com/DiegoVictor/deliveryman/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=Deliveryman\u0026uri=https%3A%2F%2Fraw.githubusercontent.com%2FDiegoVictor%2Fdeliveryman%2Fmaster%2FInsomnia_2024-12-15.json)\n\nPermit to register clients, deliverymen, deliveries and manage deliveries status (in progress, done, etc). The app has friendly errors, use JWT to logins, validation, also a simple versioning was made.\n\n## Table of Contents\n* [Installing](#installing)\n  * [Configuring](#configuring)\n    * [.env](#env)\n    * [Postgres](#postgres)\n      * [Migrations](#migrations)\n* [Usage](#usage)\n  * [Error Handling](#error-handling)\n    * [Errors Reference](#errors-reference)\n  * [Bearer Token](#bearer-token)\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: [Postgres](https://www.postgresql.org/). 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 JWT settings, database connection, 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|PORT|Port number where the app will run.|`3333`\n|JWT_CLIENTS_SECRET|A alphanumeric random string. Used to create signed tokens for clients logins.| -\n|JWT_DELIVERYMAN_SECRET|A alphanumeric random string. Used to create signed tokens for deliverymen logins.| -\n|JWT_EXPIRATION|How long time will be the token valid. See [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken#usage) repo for more information.|`1d`\n|DATABASE_URL|Database url.|`postgresql://postgres:docker@localhost:5432/deliveryman?schema=public`\n|DOCS_URL|An url to docs where users can find more information about the app's internal code errors.|`https://github.com/DiegoVictor/deliveryman#errors-reference`\n\n### Postgres\nResponsible to store all application data. If for any reason you would like to create a Postgres container instead of use `docker-compose`, you can do it by running the following command:\n```\n$ docker run --name deliveryman-postgres -e POSTGRES_PASSWORD=docker -p 5432:5432 -d postgres\n```\n\n#### Migrations\nRemember to run the Postgres database migrations:\n```\n$ npx prisma migrate deploy\n```\nOr:\n```\n$ yarn prisma migrate deploy\n```\n\u003e See more information on [migrate deploy](https://www.prisma.io/docs/reference/api-reference/command-reference#migrate-deploy).\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\": \"Username or password incorrect\",\n  \"code\": 140,\n  \"docs\": \"https://github.com/DiegoVictor/deliveryman#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|Username or password incorrect|User and/or password is incorrect.\n|240|Client already exists|The provided client's username is already in use.\n|340|Deliveryman already exists|The provided deliveryman's username is already in use.\n|440|Missing authentication token|The authentication token was not sent.\n|441|Invalid authentication token|The authentication token provided is invalid or expired.\n\n## Bearer Token\nA few 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/v1/deliveryman/deliveries Authorization: Bearer \u003ctoken\u003e\n```\n\u003e To achieve this token you just need authenticate through the `/sessions` route and it will return the `token` key with a valid Bearer Token.\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/deliveryman/deliveries\n```\n\n## Routes\n|route|HTTP Method|params|description|auth method\n|:---|:---:|:---:|:---:|:---:\n|`/clients`|POST|Body with client's `username` and `password`.|Create a new client|:x:\n|`/clients/auth`|POST|Body with client's `username` and `password`.|Authenticates clients, return a Bearer Token.|:x:\n|`/clients/deliveries`|GET| - |Retrieve client's deliveries.|Bearer (Client)\n|`/clients/deliveries`|POST|Body with delivery's `product_name`.|Create a new delivery.|Bearer (Client)\n|`/deliveryman`|POST|Body with deliveryman's `username` and `password`.|Create a new deliveryman.|:x:\n|`/deliveryman/auth`|POST|Body with deliveryman's `username` and `password`.|Authenticates deliveryman, return a Bearer Token.|:x:\n|`/deliveryman/deliveries`|GET| - |Retrieve deliveryman's deliveries.|Bearer (Deliveryman)\n|`/deliveries/not_delivered`|GET| - |Retrieve pending deliveries.|Bearer (Deliveryman)\n|`/deliveries/:id/set_deliveryman`|PATCH| - |Set deliveryman from the token as the responsible for the delivery.|Bearer (Deliveryman)\n|`/deliveries/:id/set_as_delivered`|PATCH| - |Set delivery as delivered.|Bearer (Deliveryman)\n\n### Requests\n* `POST /clients`\n\nRequest body:\n```json\n{\n  \"username\": \"johndoe\",\n  \"password\": \"123456\"\n}\n```\n\n* `POST /clients/auth`\n\nRequest body:\n```json\n{\n  \"username\": \"johndoe\",\n  \"password\": \"123456\"\n}\n```\n\n* `POST /clients/deliveries`\n\nRequest body:\n```json\n{\n  \"product_name\": \"Lemon Ice Cream\"\n}\n```\n\n* `POST /deliveryman`\n\nRequest body:\n```json\n{\n  \"username\": \"janedoe\",\n  \"password\": \"123456\"\n}\n```\n\n* `POST /deliveryman/auth`\n\nRequest body:\n```json\n{\n  \"username\": \"janedoe\",\n  \"password\": \"123456\"\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%2Fdeliveryman","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiegovictor%2Fdeliveryman","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegovictor%2Fdeliveryman/lists"}