Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 197 additions & 0 deletions semana22/WireCard/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
{
"root": true,
"env": {
"browser": true,
"es2020": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"settings": {
"react": {
"version": "detect"
}
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 11,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"no-cond-assign": ["error", "always"],
"no-console": ["warn", {"allow": ["info", "warn", "error"]}],
"no-constant-condition": "error",
"no-debugger": "error",
"no-dupe-else-if": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty": "warn",
"no-empty-character-class": "error",
"no-extra-boolean-cast": "warn",
"no-extra-parens": "off",
"@typescript-eslint/no-extra-parens": ["warn", "all", { "ignoreJSX": "multi-line" }],
"no-extra-semi": "warn",
"no-func-assign": "warn",
"no-import-assign": "warn",
"no-inner-declarations": ["warn", "both"],
"no-invalid-regexp": "error",
"no-irregular-whitespace": ["warn", {
"skipRegExps": true,
"skipTemplates": true
}],
"no-loss-of-precision": "warn",
"no-misleading-character-class": "warn",
"no-obj-calls": "warn",
"no-prototype-builtins": "error",
"no-sparse-arrays": "error",
"no-template-curly-in-string": "warn",
"no-unexpected-multiline": "warn",
"no-unreachable": "error",
"no-unreachable-loop": "error",
"no-unsafe-finally": "error",
"no-unsafe-negation": "error",
"use-isnan": "warn",
"valid-typeof": "error",

"curly": ["warn", "multi", "consistent"],
"no-empty-function": "warn",

"array-bracket-newline": ["warn", { "multiline": true }],
"array-bracket-spacing": ["warn", "always"],
"array-element-newline": ["warn", { "multiline": true, "minItems": 3 }],
"block-spacing": "warn",
"brace-style": ["warn", "1tbs", { "allowSingleLine": true }],
"capitalized-comments": "warn",
"camelcase": "off",
"comma-dangle": ["warn", "never"],
"comma-spacing": ["warn", { "before": false, "after": true }],
"comma-style": ["warn", "last"],
"computed-property-spacing": "warn",
"eol-last": ["warn", "always"],
"func-call-spacing": ["error", "never"],
"func-names": ["error", "always"],
"func-style": ["error", "declaration", { "allowArrowFunctions": true }],
"function-call-argument-newline": ["warn", "consistent"],
"function-paren-newline": ["warn", "multiline"],
"id-length": ["warn", { "min": 3, "exceptions": ["id", "_"] }],
"implicit-arrow-linebreak": ["warn", "beside"],
"indent": ["warn", 2, {
"SwitchCase": 1,
"VariableDeclarator": "first",
"MemberExpression": 1,
"FunctionDeclaration": {"parameters": "first"},
"FunctionExpression": {"parameters": "first"},
"CallExpression": {"arguments": "first"},
"ArrayExpression": "first",
"ObjectExpression": "first",
"ImportDeclaration": "first",
"flatTernaryExpressions": false,
"offsetTernaryExpressions": true,
"ignoreComments": false
}],
"jsx-quotes": ["warn", "prefer-double"],
"key-spacing": ["warn", {
"beforeColon": false,
"afterColon": true,
"mode": "strict" ,
"align": "value"
}],
"keyword-spacing": "warn",
"linebreak-style": ["warn", "unix"],
"lines-around-comment": ["warn", {
"beforeBlockComment": true,
"afterBlockComment": true,
"beforeLineComment": true,
"afterLineComment": false
}],
"lines-between-class-members": ["warn", "always"],
"max-depth": ["warn", 4],
"max-len": ["warn", { "code": 85 }],
"max-lines-per-function": ["warn", {
"max": 100,
"skipBlankLines": true,
"skipComments": true
}],
"max-nested-callbacks": ["warn", 3],
"max-params": ["warn", 6],
"max-statements-per-line": ["warn", { "max": 2 }],
"multiline-comment-style": ["warn", "bare-block"],
"multiline-ternary": ["warn", "always-multiline"],
"newline-per-chained-call": ["warn", { "ignoreChainWithDepth": 3 }],
"no-lonely-if": "warn",
"no-mixed-spaces-and-tabs": "warn",
"no-multi-assign": "warn",
"no-multiple-empty-lines": ["warn", { "max": 1 }],
"no-negated-condition": "warn",
"no-nested-ternary": "warn",
"no-new-object": "error",
"no-tabs": "warn",
"no-trailing-spaces": "warn",
"no-unneeded-ternary": "warn",
"no-whitespace-before-property": "warn",
"nonblock-statement-body-position": ["warn", "below"],
"object-curly-newline": ["warn", {
"ObjectExpression": { "multiline": true, "minProperties": 4 },
"ObjectPattern": { "multiline": true, "minProperties": 4 },
"ImportDeclaration": { "multiline": true, "minProperties": 4 },
"ExportDeclaration": { "multiline": true, "minProperties": 4 }
}],
"object-curly-spacing": ["warn", "always"],
"object-property-newline": "warn",
"one-var": ["warn", { "initialized": "never" }],
"one-var-declaration-per-line": ["warn", "initializations"],
"operator-assignment": ["warn", "always"],
"operator-linebreak": ["warn", "before"],
"padded-blocks": ["warn", "never", { "allowSingleLineBlocks": true } ],
"prefer-exponentiation-operator": "warn",
"prefer-object-spread": "warn",
"quote-props": ["warn", "as-needed"],
"quotes": ["warn", "double"],
"semi": ["warn", "always"],
"semi-spacing": ["warn", {"before": false, "after": true}],
"semi-style": ["warn", "last"],
"space-before-blocks": "warn",
"space-before-function-paren": ["warn", {"anonymous": "always", "named": "never", "asyncArrow": "always"}],
"space-in-parens": ["warn", "never"],
"space-infix-ops": "warn",
"space-unary-ops": [ "warn", {"words": true, "nonwords": false}],
"spaced-comment": ["warn", "never"],
"switch-colon-spacing": "warn",
"template-tag-spacing": "warn",
"wrap-regex": "warn",

"arrow-body-style": ["warn", "as-needed"],
"arrow-parens": ["warn", "always"],
"arrow-spacing": "warn",
"constructor-super": "error",
"generator-star-spacing": ["warn", "before"],
"no-class-assign": "error",
"no-confusing-arrow": "warn",
"no-const-assign": "error",
"no-duplicate-imports": ["error", { "includeExports": true }],
"no-new-symbol": "error",
"no-useless-computed-key": "warn",
"no-useless-constructor": "error",
"no-useless-rename": "warn",
"no-var": "warn",
"prefer-arrow-callback": "warn",
"prefer-const": "warn",
"prefer-numeric-literals": "warn",
"prefer-rest-params": "error",
"prefer-spread": "warn",
"prefer-template": "warn",
"require-yield": "error",
"rest-spread-spacing": ["warn", "never"],
"symbol-description": "error",
"template-curly-spacing": "warn",
"yield-star-spacing": ["warn", "before"],

"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }]
}
}
5 changes: 5 additions & 0 deletions semana22/WireCard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_module
build
.env
package-lock.json
yarn.lock
8 changes: 8 additions & 0 deletions semana22/WireCard/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
roots: ["<rootDir>/tests"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
};
6 changes: 6 additions & 0 deletions semana22/WireCard/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"verbose": true,
"ignore": ["build", "node_modules"],
"ext": "ts,yml",
"watch": ["src"]
}
41 changes: 41 additions & 0 deletions semana22/WireCard/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "aula58",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "tsc && node build/index.js",
"lint": "eslint --fix ./src",
"test": "jest",
"dev": "nodemon src/index.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"jest": "^27.0.6",
"jsonwebtoken": "^8.5.1",
"knex": "^0.95.7",
"mysql": "^2.18.1",
"swagger-ui-express": "^4.1.6",
"ts-jest": "^27.0.5",
"typescript": "^4.3.5",
"uuid": "^8.3.2",
"yaml": "^1.10.2",
"yup": "^0.32.9"
},
"devDependencies": {
"@types/bcryptjs": "^2.4.2",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/jsonwebtoken": "^8.5.4",
"@types/node": "^16.6.1",
"@types/swagger-ui-express": "^4.1.3",
"@types/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^4.29.2"
}
}
11 changes: 11 additions & 0 deletions semana22/WireCard/src/@types/commons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type ID = string;

export type Token = string;

export interface ApplicationErrorInterface {
initialError: any; //eslint-disable-line
name: string;
message: string;
httpStatus: number;
getMessage: () => string;
}
7 changes: 7 additions & 0 deletions semana22/WireCard/src/@types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from "./commons";

//Veja https://knexjs.org/#typescript-support
declare module "knex/types/tables" {
interface Tables {
}
}
Empty file.
6 changes: 6 additions & 0 deletions semana22/WireCard/src/commons/id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { v1 as uuidV1 } from "uuid";
import { ID } from "../@types";

export function generateId(): ID {
return uuidV1();
}
3 changes: 3 additions & 0 deletions semana22/WireCard/src/commons/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./token";
export * from "./password";
export * from "./id";
12 changes: 12 additions & 0 deletions semana22/WireCard/src/commons/password.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as bcrypt from "bcryptjs";

export async function encryptPassword(password: string): Promise<string> {
const rounds = Number(process.env.CRYPTO_ROUNDS);
const salt = await bcrypt.genSalt(rounds);
return await bcrypt.hash(password, salt);
}

export async function comparePassword(plainPassword: string, hashPassword: string)
: Promise<boolean> {
return await bcrypt.compare(plainPassword, hashPassword);
}
26 changes: 26 additions & 0 deletions semana22/WireCard/src/commons/token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as jwt from "jsonwebtoken";
import { Token } from "../@types";

export function generateToken(payload: unknown): Token {
return jwt.sign(
payload as Buffer,
process.env.TOKEN_SECRET_KEY as string,
{ expiresIn: process.env.TOKEN_DURATION }
);
}

/*
Export function generateUserToken(userTokenData: UserTokenData): Token {
return generateToken(userTokenData);
}

export async function getUserToken(token: Token): Promise<UserTokenData> {
try {
const result = jwt.verify(token, process.env.TOKEN_SECRET_KEY as string);
await validate(UserTokenDataSchema, result);
return result as UserTokenData;
} catch (error) {
throw applicationError(errorName.InvalidToken, error);
}
}
*/
Empty file.
15 changes: 15 additions & 0 deletions semana22/WireCard/src/data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import knex from "knex";

export * from "./databaseSQL";

export const databaseConnection = knex({
client: process.env.DATABASE_TYPE,
connection: {
host: process.env.DATABASE_HOST,
port: Number(process.env.DATABASE_PORT),
database: process.env.DATABASE_SCHEMA,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
multipleStatements: true
}
});
Loading