From 9bdadc2d02463ed59866c45239cb9b01f6ad3266 Mon Sep 17 00:00:00 2001 From: Talysson Date: Thu, 30 Sep 2021 10:25:52 -0300 Subject: [PATCH 01/56] Clean state before migration --- .editorconfig | 13 - .env | 0 .eslintrc | 18 - .gitignore | 25 - .nvmrc | 1 - .nycrc | 13 - .sequelizerc | 8 - LICENSE.md | 21 - Procfile | 1 - README.md | 114 - cluster.js | 35 - config/database.js.example | 18 - config/environments/development.js | 14 - config/environments/production.js | 10 - config/environments/test.js | 3 - config/index.js | 27 - index.js | 10 - logs/.gitkeep | 0 package.json | 65 - scripts/cleanup.js | 94 - src/app/Application.js | 21 - src/app/Operation.js | 27 - src/app/user/CreateUser.js | 31 - src/app/user/DeleteUser.js | 27 - src/app/user/GetAllUsers.js | 26 - src/app/user/GetUser.js | 26 - src/app/user/UpdateUser.js | 32 - src/app/user/index.js | 7 - src/container.js | 79 - src/domain/user/User.js | 18 - src/infra/database/migrate/.gitkeep | 0 .../migrate/20170308131539-create-user.js | 27 - src/infra/database/models/User.js | 15 - src/infra/database/models/index.js | 17 - src/infra/database/seeds/.gitkeep | 0 .../seeds/20170308131757-test-users.js | 23 - src/infra/factoryGirl/FactoriesLoader.js | 20 - src/infra/factoryGirl/index.js | 3 - src/infra/logging/LoggerStreamAdapter.js | 11 - src/infra/logging/logger.js | 7 - src/infra/sequelize/ModelsLoader.js | 29 - src/infra/sequelize/index.js | 3 - src/infra/support/dataFaker.js | 4 - src/infra/user/SequelizeUserMapper.js | 17 - src/infra/user/SequelizeUsersRepository.js | 91 - src/interfaces/console/Console.js | 33 - src/interfaces/console/index.js | 8 - src/interfaces/http/Server.js | 25 - src/interfaces/http/errors/devErrorHandler.js | 14 - src/interfaces/http/errors/errorHandler.js | 13 - .../http/logging/loggerMiddleware.js | 8 - src/interfaces/http/router.js | 48 - src/interfaces/http/swagger/swagger.json | 249 - .../http/swagger/swaggerMiddleware.js | 4 - src/interfaces/http/user/UserSerializer.js | 10 - src/interfaces/http/user/UsersController.js | 125 - .../http/utils/createControllerRoutes.js | 8 - test/features/api/.gitkeep | 0 test/features/api/users/createUser.spec.js | 31 - test/features/api/users/deleteUser.spec.js | 31 - test/features/api/users/listUsers.spec.js | 38 - test/features/api/users/showUser.spec.js | 31 - test/features/api/users/updateUser.spec.js | 58 - test/mocha.opts.features | 3 - test/mocha.opts.unit | 3 - test/setup.js | 10 - test/support/cleanDatabase.js | 4 - test/support/factories/.gitkeep | 0 test/support/factories/user.js | 7 - test/support/factory.js | 13 - test/support/request.js | 5 - test/unit/app/Operation.spec.js | 36 - test/unit/app/user/CreateUser.spec.js | 75 - test/unit/app/user/DeleteUser.spec.js | 70 - test/unit/app/user/GetAllUsers.spec.js | 49 - test/unit/app/user/GetUser.spec.js | 54 - test/unit/app/user/UpdateUser.spec.js | 101 - test/unit/domain/user/User.spec.js | 22 - .../infra/logging/LoggerStreamAdapter.spec.js | 22 - .../infra/user/SequelizeUserMapper.spec.js | 35 - .../user/SequelizeUsersRepository.spec.js | 173 - .../http/user/UserSerializer.spec.js | 40 - yarn.lock | 4228 ----------------- 83 files changed, 6735 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .env delete mode 100644 .eslintrc delete mode 100644 .gitignore delete mode 100644 .nvmrc delete mode 100644 .nycrc delete mode 100644 .sequelizerc delete mode 100644 LICENSE.md delete mode 100644 Procfile delete mode 100644 README.md delete mode 100644 cluster.js delete mode 100644 config/database.js.example delete mode 100644 config/environments/development.js delete mode 100644 config/environments/production.js delete mode 100644 config/environments/test.js delete mode 100644 config/index.js delete mode 100644 index.js delete mode 100644 logs/.gitkeep delete mode 100644 package.json delete mode 100644 scripts/cleanup.js delete mode 100644 src/app/Application.js delete mode 100644 src/app/Operation.js delete mode 100644 src/app/user/CreateUser.js delete mode 100644 src/app/user/DeleteUser.js delete mode 100644 src/app/user/GetAllUsers.js delete mode 100644 src/app/user/GetUser.js delete mode 100644 src/app/user/UpdateUser.js delete mode 100644 src/app/user/index.js delete mode 100644 src/container.js delete mode 100644 src/domain/user/User.js delete mode 100644 src/infra/database/migrate/.gitkeep delete mode 100644 src/infra/database/migrate/20170308131539-create-user.js delete mode 100644 src/infra/database/models/User.js delete mode 100644 src/infra/database/models/index.js delete mode 100644 src/infra/database/seeds/.gitkeep delete mode 100644 src/infra/database/seeds/20170308131757-test-users.js delete mode 100644 src/infra/factoryGirl/FactoriesLoader.js delete mode 100644 src/infra/factoryGirl/index.js delete mode 100644 src/infra/logging/LoggerStreamAdapter.js delete mode 100644 src/infra/logging/logger.js delete mode 100644 src/infra/sequelize/ModelsLoader.js delete mode 100644 src/infra/sequelize/index.js delete mode 100644 src/infra/support/dataFaker.js delete mode 100644 src/infra/user/SequelizeUserMapper.js delete mode 100644 src/infra/user/SequelizeUsersRepository.js delete mode 100644 src/interfaces/console/Console.js delete mode 100644 src/interfaces/console/index.js delete mode 100644 src/interfaces/http/Server.js delete mode 100644 src/interfaces/http/errors/devErrorHandler.js delete mode 100644 src/interfaces/http/errors/errorHandler.js delete mode 100644 src/interfaces/http/logging/loggerMiddleware.js delete mode 100644 src/interfaces/http/router.js delete mode 100644 src/interfaces/http/swagger/swagger.json delete mode 100644 src/interfaces/http/swagger/swaggerMiddleware.js delete mode 100644 src/interfaces/http/user/UserSerializer.js delete mode 100644 src/interfaces/http/user/UsersController.js delete mode 100644 src/interfaces/http/utils/createControllerRoutes.js delete mode 100644 test/features/api/.gitkeep delete mode 100644 test/features/api/users/createUser.spec.js delete mode 100644 test/features/api/users/deleteUser.spec.js delete mode 100644 test/features/api/users/listUsers.spec.js delete mode 100644 test/features/api/users/showUser.spec.js delete mode 100644 test/features/api/users/updateUser.spec.js delete mode 100644 test/mocha.opts.features delete mode 100644 test/mocha.opts.unit delete mode 100644 test/setup.js delete mode 100644 test/support/cleanDatabase.js delete mode 100644 test/support/factories/.gitkeep delete mode 100644 test/support/factories/user.js delete mode 100644 test/support/factory.js delete mode 100644 test/support/request.js delete mode 100644 test/unit/app/Operation.spec.js delete mode 100644 test/unit/app/user/CreateUser.spec.js delete mode 100644 test/unit/app/user/DeleteUser.spec.js delete mode 100644 test/unit/app/user/GetAllUsers.spec.js delete mode 100644 test/unit/app/user/GetUser.spec.js delete mode 100644 test/unit/app/user/UpdateUser.spec.js delete mode 100644 test/unit/domain/user/User.spec.js delete mode 100644 test/unit/infra/logging/LoggerStreamAdapter.spec.js delete mode 100644 test/unit/infra/user/SequelizeUserMapper.spec.js delete mode 100644 test/unit/infra/user/SequelizeUsersRepository.spec.js delete mode 100644 test/unit/interfaces/http/user/UserSerializer.spec.js delete mode 100644 yarn.lock diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index d08e1e6..0000000 --- a/.editorconfig +++ /dev/null @@ -1,13 +0,0 @@ -# http://editorconfig.org -root = true - -[*] -charset = utf-8 -end_of_line = lf -indent_style = space -indent_size = 2 -trim_trailing_whitespace = true -insert_final_newline = true - -[*.md] -trim_trailing_whitespace = false diff --git a/.env b/.env deleted file mode 100644 index e69de29..0000000 diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 093f86e..0000000 --- a/.eslintrc +++ /dev/null @@ -1,18 +0,0 @@ -{ - "env": { - "node": true, - "es6": true, - "mocha": true - }, - "parserOptions": { - "ecmaVersion": 2017 - }, - "extends": "eslint:recommended", - "rules": { - "comma-spacing": ["error", { "before": false, "after": true }], - "indent": ["error", 2], - "linebreak-style": ["error", "unix"], - "quotes": ["error", "single"], - "semi": ["error", "always"] - } -} diff --git a/.gitignore b/.gitignore deleted file mode 100644 index ea4e6a1..0000000 --- a/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -# Logs -*.log - -# Node -node_modules/ - -# Project specific -config/database.js - -# Unit test / coverage reports -coverage/ -.nyc_output - -# OS auto-generated files -.DS_Store -._* - - -# Vim -*~ -*.swp -*.swo - -# IDE files -.idea/ diff --git a/.nvmrc b/.nvmrc deleted file mode 100644 index 93c8dda..0000000 --- a/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -7.6.0 diff --git a/.nycrc b/.nycrc deleted file mode 100644 index 081beb4..0000000 --- a/.nycrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "cwd": "./src", - "exclude": [ - "container.js", - "app/Application.js", - "interfaces/http" - ], - "reporter": [ - "html", - "lcov", - "text-summary" - ] -} diff --git a/.sequelizerc b/.sequelizerc deleted file mode 100644 index 555a216..0000000 --- a/.sequelizerc +++ /dev/null @@ -1,8 +0,0 @@ -const ENV = process.env.NODE_ENV || 'development'; - -module.exports = { - config: 'config/database.js', - 'migrations-path': 'src/infra/database/migrate', - 'models-path': 'src/infra/database/models', - 'seeders-path': 'src/infra/database/seeds' -}; diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index af75ca9..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,21 +0,0 @@ -# MIT License - -Copyright (c) 2018 Talysson de Oliveira Cassiano - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/Procfile b/Procfile deleted file mode 100644 index 063b78f..0000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: npm start diff --git a/README.md b/README.md deleted file mode 100644 index 1a36c1d..0000000 --- a/README.md +++ /dev/null @@ -1,114 +0,0 @@ -# Node API boilerplate - -An opinionated boilerplate for Node web APIs focused on separation of concerns and scalability. - -## Features - -
-
Multilayer folder structure
-
- Code organization inspired by DDD and Clean Architecture focused on codebase scalability. -
- -
Instant feedback and reload
-
- Use Nodemon to automatically reload the server after a file change when on development mode, makes the development faster and easier. -
- -
Ready for production
-
- Setup with PM2 process manager ready to go live on production. It's also out-of-box ready to be deployed at Heroku, you can read more about it here. -
- -
Scalable and easy to use web server
-
- Use Express for requests routing and middlewares. There are some essential middlewares for web APIs already setup, like body-parser, compression, CORS and method-override. -
- -
Database integration
-
- Sequelize, an ORM for SQL databases, is already integrated, you just have to set the authentication configurations. -
- -
Prepared for testing
-
- The test suite uses Mocha/Chai and is prepared to run unit, integration and functional tests right from the beginning. There are helpers to make it easy to make requests to the web app during the tests and for cleaning the database after each test. A FactoryGirl adapter for Sequelize is setup to make your tests DRY as well, and the tests generate code coverage measurement with Istanbul. You should read about the Chai plugins that are setup by default too. -
- -
Dependency injection
-
- With Awilix, a practical dependency injection library, the code will not be coupled and it'll still be easy to resolve automatically the dependencies on the runtime and mock them during the tests. It's even possible inject dependencies on your controllers with the Awilix Express adapter. Click here if you want to read more about how to use dependency injection with this boilerplate. -
- -
CLI integration
-
- Both the application and Sequelize have command-line tools to make it easy to work with them. Check the Scripts section to know more about this feature. -
- -
Logging
-
- The Log4js logger is highly pluggable, being able to append the messages to a file during the development and send them to a logging service when on production. Even the requests (through morgan) and queries will be logged. -
- -
Linter
-
- It's also setup with ESLint to make it easy to ensure a code styling and find code smells. -
-
- -## Quick start - -_Notice that the boilerplate comes with a small application for user management already, you can delete it with a npm script after you understand how the boilerplate works but please do the quick start first!_ 😊 - -1. Clone the repository with `git clone --depth=1 https://github.com/talyssonoc/node-api-boilerplate` -2. Setup the database on `config/database.js` (there's an example file there to be used with PostgreSQL 😉 ) -3. Install the dependencies with `yarn` (click here if [you don't have Yarn installed](https://yarnpkg.com/docs/install)) -4. Create the development and test databases you have setup on `config/database.js` -5. Run the database migrations with `npm run sequelize db:migrate` -6. Add some seed data to the development database with `npm run sequelize db:seed:all` -7. Run the application in development mode with `npm run dev` -8. Access `http://localhost:3000/api/users` and you're ready to go! - -After playing a little bit with the boilerplate and _before_ implementing a real application with it I recommend you to read at least the `Setup` and the `Organization and architecture` sections of our [Wiki](https://github.com/talyssonoc/node-api-boilerplate/wiki). After that you'll be able to remove the example application files running `npm run cleanup` - -## Aditional info: - -- Don't forget to run the migrations for the test environment as well (including when you create a new migration) with `npm run sequelize db:migrate -- --env=test` - -## Scripts - -This boilerplate comes with a collection of npm scripts to make your life easier, you'll run them with `npm run