{"id":26088954,"url":"https://github.com/notadson/codex-backend","last_synced_at":"2026-04-13T03:05:29.365Z","repository":{"id":281401314,"uuid":"931796610","full_name":"NotAdson/Codex-BackEnd","owner":"NotAdson","description":"TODO LIST REST API","archived":false,"fork":false,"pushed_at":"2025-03-08T21:27:39.000Z","size":170,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-08T21:30:04.199Z","etag":null,"topics":["express-js","jwt-authentication","mongodb-atlas","nodejs","rest-api"],"latest_commit_sha":null,"homepage":"https://codex-backend-qmnz.onrender.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NotAdson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-02-12T21:44:24.000Z","updated_at":"2025-03-08T21:27:42.000Z","dependencies_parsed_at":"2025-03-08T21:30:09.190Z","dependency_job_id":"32b09ea1-8592-471f-9127-65431e79c63b","html_url":"https://github.com/NotAdson/Codex-BackEnd","commit_stats":null,"previous_names":["notadson/codex-backend"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/NotAdson/Codex-BackEnd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotAdson%2FCodex-BackEnd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotAdson%2FCodex-BackEnd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotAdson%2FCodex-BackEnd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotAdson%2FCodex-BackEnd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NotAdson","download_url":"https://codeload.github.com/NotAdson/Codex-BackEnd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotAdson%2FCodex-BackEnd/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259602374,"owners_count":22882977,"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":["express-js","jwt-authentication","mongodb-atlas","nodejs","rest-api"],"created_at":"2025-03-09T08:44:21.368Z","updated_at":"2026-04-13T03:05:29.338Z","avatar_url":"https://github.com/NotAdson.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TODO List API\n\nThis document provides detailed information about the REST API for managing users and tasks. The API is built using Express.js and follows a structured project layout.\n\n---\n\n## Table of Contents\n1. [Project Structure](#project-structure)\n2. [User Routes](#user-routes)\n   - [Register User](#register-user)\n   - [Login User](#login-user)\n   - [Get User by ID](#get-user-by-id)\n   - [Update User](#update-user)\n   - [Delete User](#delete-user)\n3. [Task Routes](#task-routes)\n   - [Create Task](#create-task)\n   - [Get Tasks by User](#get-tasks-by-user)\n   - [Update Task](#update-task)\n   - [Delete Task](#delete-task)\n4. [Validation Rules](#validation-rules)\n   - [User Validation](#user-validation)\n   - [Task Validation](#task-validation)\n5. [Authentication](#authentication)\n6. [Running the Project](#running-the-project)\n\n---\n\n## Project Structure\n\nThe project is organized as follows:\n\n```\n├── package.json\n├── package-lock.json\n├── src\n│   ├── authentication\n│   │   └── Authenticator.js\n│   ├── controllers\n│   │   ├── TaskController.js\n│   │   └── UserController.js\n│   ├── database\n│   │   └── connection.js\n│   ├── middleware\n│   │   ├── Task.validator.js\n│   │   └── User.validator.js\n│   ├── models\n│   │   ├── Task.js\n│   │   └── User.js\n│   ├── routes\n│   │   ├── Task.routes.js\n│   │   └── User.routes.js\n│   ├── services\n│   │   ├── TaskService.js\n│   │   └── UserService.js\n│   ├── shared\n│   │   └── messages.js\n│   └── __tests__\n│       ├── Authenticator.test.js\n│       ├── jest.globalSetup.js\n│       ├── jest.globalTeardown.js\n│       ├── TaskController.test.js\n│       ├── Task.routes.test.js\n│       ├── TaskService.test.js\n│       ├── UserController.test.js\n│       ├── User.routes.test.js\n│       └── UserService.test.js\n└── startServer.js\n```\n\n---\n\n## User Routes\n\n### Register User\n\n- **Endpoint**: `POST /api/register-user`\n- **Description**: Registers a new user.\n- **Authentication**: Not required.\n- **Request Body**:\n  ```json\n  {\n    \"name\": \"Caba legal\",\n    \"email\": \"caba@legal.com\",\n    \"password\": \"senha123\"\n  }\n  ```\n- **Response**:\n  - Success: `201 Created`\n  - Error: `400 Bad Request` (if validation fails) or `500 Internal Server Error`\n\n---\n\n### Login User\n\n- **Endpoint**: `POST /api/login`\n- **Description**: Authenticates a user and returns an access token.\n- **Authentication**: Not required.\n- **Request Body**:\n  ```json\n  {\n    \"email\": \"caba@legal.com\",\n    \"password\": \"senha123\"\n  }\n  ```\n- **Response**:\n  - Success: `200 OK` with access token\n    ```json\n    {\n      \"message\": \"Login successful.\",\n      \"accessToken\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\"\n    }\n    ```\n  - Error: `400 Bad Request` (if validation fails) or `500 Internal Server Error`\n\n---\n\n### Get User by ID\n\n- **Endpoint**: `GET /api/user`\n- **Description**: Retrieves the authenticated user's details using the JWT token.\n- **Authentication**: Required (JWT token).\n- **Request Headers**:\n  - `Authorization: Bearer \u003caccess_token\u003e`\n- **Response**:\n  - Success: `200 OK` with user data\n    ```json\n    {\n      \"id\": \"123\",\n      \"name\": \"Caba legal\",\n      \"email\": \"caba@legal.com\"\n    }\n    ```\n  - Error: `401 Unauthorized` (if token is invalid) or `500 Internal Server Error`\n\n---\n\n### Update User\n\n- **Endpoint**: `PUT /api/user/update`\n- **Description**: Updates the authenticated user's details.\n- **Authentication**: Required (JWT token).\n- **Request Headers**:\n  - `Authorization: Bearer \u003caccess_token\u003e`\n- **Request Body**:\n  ```json\n  {\n    \"name\": \"Updated Name\",\n    \"email\": \"updated.email@example.com\"\n  }\n  ```\n- **Response**:\n  - Success: `200 OK`\n  - Error: `400 Bad Request` (if validation fails) or `500 Internal Server Error`\n\n---\n\n### Delete User\n\n- **Endpoint**: `DELETE /api/user/delete`\n- **Description**: Deletes the authenticated user.\n- **Authentication**: Required (JWT token).\n- **Request Headers**:\n  - `Authorization: Bearer \u003caccess_token\u003e`\n- **Response**:\n  - Success: `200 OK`\n  - Error: `400 Bad Request` (if validation fails) or `500 Internal Server Error`\n\n---\n\n## Task Routes\n\n### Create Task\n\n- **Endpoint**: `POST /api/task/create`\n- **Description**: Creates a new task for the authenticated user.\n- **Authentication**: Required (JWT token).\n- **Request Headers**:\n  - `Authorization: Bearer \u003caccess_token\u003e`\n- **Request Body**:\n  ```json\n  {\n    \"title\": \"Complete API Documentation\"\n  }\n  ```\n- **Response**:\n  - Success: `201 Created`\n  - Error: `400 Bad Request` (if validation fails) or `500 Internal Server Error`\n\n---\n\n### Get Tasks by User\n\n- **Endpoint**: `GET /api/tasks`\n- **Description**: Retrieves all tasks for the authenticated user.\n- **Authentication**: Required (JWT token).\n- **Request Headers**:\n  - `Authorization: Bearer \u003caccess_token\u003e`\n- **Response**:\n  - Success: `200 OK` with list of tasks\n    ```json\n    [\n      {\n        \"id\": \"1\",\n        \"title\": \"Complete API Documentation\",\n        \"completed\": false\n      }\n    ]\n    ```\n  - Error: `400 Bad Request` (if validation fails) or `500 Internal Server Error`\n\n---\n\n### Update Task\n\n- **Endpoint**: `PUT /api/task/update/:id`\n- **Description**: Updates an existing task by its ID.\n- **Authentication**: Required (JWT token).\n- **Request Headers**:\n  - `Authorization: Bearer \u003caccess_token\u003e`\n- **Request Params**:\n  - `id`: Task ID (required)\n- **Request Body**:\n  ```json\n  {\n    \"title\": \"Updated Task Title\",\n    \"completed\": true\n  }\n  ```\n- **Response**:\n  - Success: `200 OK`\n  - Error: `400 Bad Request` (if validation fails) or `500 Internal Server Error`\n\n---\n\n### Delete Task\n\n- **Endpoint**: `DELETE /api/task/delete/:id`\n- **Description**: Deletes a task by its ID.\n- **Authentication**: Required (JWT token).\n- **Request Headers**:\n  - `Authorization: Bearer \u003caccess_token\u003e`\n- **Request Params**:\n  - `id`: Task ID (required)\n- **Response**:\n  - Success: `200 OK`\n  - Error: `400 Bad Request` (if validation fails) or `500 Internal Server Error`\n\n---\n\n## Validation Rules\n\n### User Validation\n\n- **Register User**:\n  - Fields: `name`, `email`, `password` (all required).\n  - Errors: Missing fields will return `400 Bad Request` with a list of errors.\n- **Login User**:\n  - Fields: `email`, `password` (all required).\n  - Errors: Missing fields will return `400 Bad Request`.\n- **Get User**:\n  - Fields: `userId` (extracted from JWT token).\n  - Errors: Missing `userId` will return `400 Bad Request`.\n- **Update User**:\n  - Fields: `userId` (extracted from JWT token), `updateData` (cannot be empty).\n  - Errors: Missing `userId` or empty `updateData` will return `400 Bad Request`.\n- **Delete User**:\n  - Fields: `userId` (extracted from JWT token).\n  - Errors: Missing `userId` will return `400 Bad Request`.\n\n### Task Validation\n\n- **Create Task**:\n  - Fields: `title` (required).\n  - Errors: Missing fields will return `400 Bad Request`.\n- **Get Tasks**:\n  - Fields: `userId` (extracted from JWT token).\n  - Errors: Missing `userId` will return `400 Bad Request`.\n- **Update Task**:\n  - Fields: `id` (required), `updateData` (cannot be empty).\n  - Errors: Missing `id` or empty `updateData` will return `400 Bad Request`.\n- **Delete Task**:\n  - Fields: `id` (required).\n  - Errors: Missing `id` will return `400 Bad Request`.\n\n---\n\n## Authentication\n\n- **JWT Token**: Required for all task routes and user update/delete routes.\n- **Middleware**: `verifyJWT` is used to validate the token.\n- **Token Expiration**: Access tokens expire after `1 hour`.\n\n---\n\n## Running the Project\n\n1. Install dependencies:\n   ```bash\n   npm install\n   ```\n2. Start the server:\n   ```bash\n   npm start\n   ```\n3. Run tests:\n   ```bash\n   npm test\n   ```\n4. Run tests in watch mode:\n   ```bash\n   npm run test:watch\n   ```\n\n---\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotadson%2Fcodex-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnotadson%2Fcodex-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotadson%2Fcodex-backend/lists"}