Skip to content

Commit 539ba25

Browse files
first commit
0 parents  commit 539ba25

32 files changed

+6863
-0
lines changed

.editorconfig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# Unix-style newlines with a newline ending every file
5+
[*]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
9+
# Matches multiple files with brace expansion notation
10+
# Set default charset
11+
[*.{js,jsx,ts,tsx,css,scss,html,json,md}]
12+
charset = utf-8
13+
14+
# 4 space indentation
15+
[*.js]
16+
indent_style = space
17+
indent_size = 2
18+
19+
[*.ts]
20+
indent_style = space
21+
indent_size = 2
22+
23+
# Matches the exact files either package.json or .travis.yml
24+
[{package.json,.travis.yml}]
25+
indent_style = space
26+
indent_size = 2

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DATABASE_STRING=
2+
KEY=
3+
CLIENT_ID=
4+
PASSWORD_MASTER=
5+
FROM=
6+
SENDGRID_API_KEY=
7+

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
/*.js
3+
src/swagger.ts

.eslintrc.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"env": {
3+
"es2020": true,
4+
"node": true,
5+
"jest": true
6+
},
7+
"extends": ["standard", "plugin:@typescript-eslint/recommended"],
8+
"parser": "@typescript-eslint/parser",
9+
"overrides": [
10+
{
11+
"files": ["*.ts"],
12+
"parserOptions": {
13+
"project": ["./tsconfig.json"]
14+
}
15+
}
16+
],
17+
"parserOptions": {
18+
"ecmaVersion": 11,
19+
"sourceType": "module"
20+
},
21+
"plugins": ["@typescript-eslint"],
22+
"rules": {
23+
"@typescript-eslint/no-unused-vars": "off",
24+
"@typescript-eslint/explicit-module-boundary-types": "off",
25+
"no-unused-vars": "off",
26+
"@typescript-eslint/no-floating-promises": "error",
27+
"space-before-function-paren": "off",
28+
"no-useless-constructor": "off"
29+
}
30+
}

.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# Compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
/bazel-out
8+
9+
# Node
10+
/node_modules
11+
npm-debug.log
12+
yarn-error.log
13+
14+
# IDEs and editors
15+
.idea/
16+
.project
17+
.classpath
18+
.c9/
19+
*.launch
20+
.settings/
21+
*.sublime-workspace
22+
23+
# Visual Studio Code
24+
.vscode/*
25+
!.vscode/settings.json
26+
!.vscode/tasks.json
27+
!.vscode/launch.json
28+
!.vscode/extensions.json
29+
.history/*
30+
31+
# Miscellaneous
32+
/.angular/cache
33+
.sass-cache/
34+
/connect.lock
35+
/coverage
36+
/libpeerconnection.log
37+
testem.log
38+
/typings
39+
40+
# System files
41+
.DS_Store
42+
Thumbs.db
43+
.vscode
44+
.env

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 180,
3+
"singleQuote": true,
4+
"trailingComma": "none",
5+
"semi": false
6+
}

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Development the API Clean Architecture Node.js with TypeScript
2+
3+
```plaintext
4+
src/
5+
├── entities/
6+
│ └── User.ts
7+
├── useCases/
8+
│ └── createUser/
9+
│ ├── CreateUserUseCase.ts
10+
│ ├── ICreateUserRepository.ts
11+
│ └── CreateUserController.ts
12+
├── adapters/
13+
│ ├── controllers/
14+
│ │ └── UserController.ts
15+
│ ├── repositories/
16+
│ │ └── UserRepository.ts
17+
│ └── presenters/
18+
│ └── UserPresenter.ts
19+
├── frameworks/
20+
│ ├── express/
21+
│ │ ├── server.ts
22+
│ │ └── middlewares/
23+
│ │ └── ExampleMiddleware.ts
24+
│ └── typeorm/
25+
│ ├── entities/
26+
│ │ └── UserEntity.ts
27+
│ └── database.ts
28+
├── services/
29+
│ └── UserService.ts
30+
├── shared/
31+
│ └── utils/
32+
│ └── Validation.ts
33+
└── index.ts
34+
```

jest.config.js

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
const { compilerOptions } = require('./tsconfig.json')
2+
const { pathsToModuleNameMapper } = require('ts-jest/utils')
3+
4+
var realFs = require('fs')
5+
var gracefulFs = require('graceful-fs')
6+
gracefulFs.gracefulify(realFs)
7+
8+
module.exports = {
9+
// All imported modules in your tests should be mocked automatically
10+
// automock: false,
11+
12+
// Stop running tests after `n` failures
13+
// bail: 1,
14+
15+
// The glob patterns Jest uses to detect test files
16+
testMatch: [
17+
// "**/__tests__/**/?(*.)+(spec|test).ts",
18+
// "**/__tests__/construction.spec.ts",
19+
// "**/src/**/account-recovery.spec.ts",
20+
"**/src/**/?(*.)+(spec|test).ts"
21+
],
22+
23+
// The directory where Jest should store its cached dependency information
24+
// cacheDirectory: "/private/var/folders/m7/3yjbp5ds77xb33vt96mwlwq00000gn/T/jest_dx",
25+
26+
// Automatically clear mock calls and instances between every test
27+
clearMocks: true,
28+
29+
testTimeout: 60000,
30+
31+
// Indicates whether the coverage information should be collected while executing the test
32+
// collectCoverage: false,
33+
34+
// An array of glob patterns indicating a set of files for which coverage information should be collected
35+
// collectCoverageFrom: undefined,
36+
37+
// The directory where Jest should output its coverage files
38+
coverageDirectory: "<rootDir>/coverage/",
39+
40+
// An array of regexp pattern strings used to skip coverage collection
41+
// coveragePathIgnorePatterns: [
42+
// "/node_modules/"
43+
// ],
44+
45+
// A list of reporter names that Jest uses when writing coverage reports
46+
coverageReporters: [
47+
"json",
48+
"text",
49+
"lcov",
50+
"clover"
51+
],
52+
53+
// An object that configures minimum threshold enforcement for coverage results
54+
// coverageThreshold: undefined,
55+
56+
// A path to a custom dependency extractor
57+
// dependencyExtractor: undefined,
58+
59+
// Make calling deprecated APIs throw helpful error messages
60+
// errorOnDeprecated: false,
61+
62+
// Force coverage collection from ignored files using an array of glob patterns
63+
// forceCoverageMatch: [],
64+
65+
// A path to a module which exports an async function that is triggered once before all test suites
66+
// globalSetup: undefined,
67+
68+
// A path to a module which exports an async function that is triggered once after all test suites
69+
// globalTeardown: undefined,
70+
71+
// A set of global variables that need to be available in all test environments
72+
// globals: {},
73+
74+
// The maximum amount of workers used to run your tests. Can be specified as % or a number.
75+
// E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
76+
// maxWorkers: "50%",
77+
78+
// An array of directory names to be searched recursively up from the requiring module's location
79+
// moduleDirectories: [
80+
// "node_modules"
81+
// ],
82+
83+
// An array of file extensions your modules use
84+
// moduleFileExtensions: [
85+
// "js",
86+
// "json",
87+
// "jsx",
88+
// "ts",
89+
// "tsx",
90+
// "node"
91+
// ],
92+
93+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
94+
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>' }),
95+
96+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
97+
// modulePathIgnorePatterns: ["<rootDir>/src/__tests__/"],
98+
99+
// Activates notifications for test results
100+
// notify: false,
101+
102+
// An enum that specifies notification mode. Requires { notify: true }
103+
// notifyMode: "failure-change",
104+
105+
// A preset that is used as a base for Jest's configuration
106+
preset: 'ts-jest',
107+
108+
// Run tests from one or more projects
109+
// projects: undefined,
110+
111+
// Use this configuration option to add custom reporters to Jest
112+
// reporters: undefined,
113+
114+
// Automatically reset mock state between every test
115+
// resetMocks: false,
116+
117+
// Reset the module registry before running each individual test
118+
// resetModules: false,
119+
120+
// A path to a custom resolver
121+
// resolver: undefined,
122+
123+
// Automatically restore mock state between every test
124+
// restoreMocks: false,
125+
126+
// The root directory that Jest should scan for tests and modules within
127+
// rootDir: undefined,
128+
129+
// A list of paths to directories that Jest should use to search for files in
130+
// roots: [
131+
// "<rootDir>"
132+
// ],
133+
134+
// Allows you to use a custom runner instead of Jest's default test runner
135+
// runner: "jest-runner",
136+
137+
// The paths to modules that run some code to configure or set up the testing environment before each test
138+
// setupFiles: [],
139+
140+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
141+
// setupFilesAfterEnv: [],
142+
143+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
144+
// snapshotSerializers: [],
145+
146+
// The test environment that will be used for testing
147+
testEnvironment: 'node',
148+
149+
// Options that will be passed to the testEnvironment
150+
// testEnvironmentOptions: {},
151+
152+
// Adds a location field to test results
153+
// testLocationInResults: false,
154+
155+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
156+
// testPathIgnorePatterns: [
157+
// "/node_modules/"
158+
// ],
159+
160+
// The regexp pattern or array of patterns that Jest uses to detect test files
161+
// testRegex: [],
162+
163+
// This option allows the use of a custom results processor
164+
// testResultsProcessor: undefined,
165+
166+
// This option allows use of a custom test runner
167+
// testRunner: "jasmine2",
168+
169+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
170+
// testURL: "http://localhost",
171+
172+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
173+
// timers: "real",
174+
175+
// A map from regular expressions to paths to transformers
176+
// transform: undefined,
177+
178+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
179+
// transformIgnorePatterns: [
180+
// "/node_modules/"
181+
// ],
182+
183+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
184+
// unmockedModulePathPatterns: undefined,
185+
186+
// Indicates whether each individual test should be reported during the run
187+
// verbose: true,
188+
189+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
190+
// watchPathIgnorePatterns: [],
191+
192+
// Whether to use watchman for file crawling
193+
// watchman: true,
194+
}

middlewares/authMaster.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require('dotenv').config();
2+
const log = require('../utils/winston');
3+
4+
const validateMaster = (req, res, next) => {
5+
try {
6+
const masterEmails = [
7+
'anderson.giusti@ibm.com',
8+
'jaque.felix@ibm.com',
9+
'lgaleoti@br.ibm.com',
10+
];
11+
12+
const email = req.headers.email;
13+
const password = req.headers.password;
14+
15+
if (masterEmails !== email && password !== process.env.PASSWORD_MASTER) {
16+
const errorMessage = 'Login or password incorrect';
17+
log.loggerError.http(errorMessage);
18+
return res.status(401).json({
19+
Message: errorMessage,
20+
Success: false,
21+
Results: null,
22+
});
23+
}
24+
25+
next();
26+
} catch (err) {
27+
const errorMessage = 'Unauthorized';
28+
log.loggerError.http(errorMessage);
29+
return res.status(401).json({
30+
Message: errorMessage,
31+
Success: false,
32+
Results: null,
33+
});
34+
}
35+
};
36+
37+
module.exports = validateMaster;

0 commit comments

Comments
 (0)