From 9e9db76e2f98525168f4ae524b77d3e5c017faf4 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Tue, 13 Aug 2024 19:48:27 -0400 Subject: [PATCH 01/70] =?UTF-8?q?chore:=20fun=C3=A7=C3=A3o=20de=20assinar?= =?UTF-8?q?=20o=20token=20criada?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auth/auth.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/auth/auth.js diff --git a/src/auth/auth.js b/src/auth/auth.js new file mode 100644 index 0000000..40b3eb5 --- /dev/null +++ b/src/auth/auth.js @@ -0,0 +1,20 @@ +import jwt from 'jsonwebtoken'; + +const dafaultExpirationDate = '4hr'; + +const JWT_SECRET = `${process.env['JWT_SECRET']}`; + +/** + * + * @param {Object.} payload + * @param {jwt.SignOptions} [options={ expiresIn: defaultTokenExpiration }] + * @returns {String} + */ +function signJWT(payload, options = {}) { + options.expiresIn = options.expiresIn || dafaultExpirationDate; + options.subject = payload.id; + payload.iat = Math.floor(Date.now() / 1000) - 30; + return jwt.sign(payload, JWT_SECRET, options); +} + +export { signJWT }; From 01877695e3765257a7e4d8c0973cf726660c5d26 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Tue, 13 Aug 2024 19:50:21 -0400 Subject: [PATCH 02/70] chore: configdotenv configurado --- src/index.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/index.js b/src/index.js index da39811..f6c5942 100644 --- a/src/index.js +++ b/src/index.js @@ -1,23 +1,25 @@ -import express from "express" -import helmet from "helmet" -import cors from "cors" -import router from "./routes/routes.js" +import express from 'express'; +import helmet from 'helmet'; +import cors from 'cors'; +import router from './routes/routes.js'; +import { configDotenv } from 'dotenv'; -const port = 3000 -const app = express() +configDotenv(); + +const port = 3000; +const app = express(); //middlewares obrigatorios -app.use(express.json()) -app.use(helmet()) -app.use(cors()) +app.use(express.json()); +app.use(helmet()); +app.use(cors()); //roteador -app.use('/',router) +app.use('/', router); //entrypoint -app.listen(port,()=>{ - console.log("Servidor ativo em: http://localhost:3000") -}) - +app.listen(port, () => { + console.log('Servidor ativo em: http://localhost:3000'); +}); -export default app \ No newline at end of file +export default app; From 77057f87a2b7d8abf01cad0f245b0f2bb5718015 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Tue, 13 Aug 2024 19:51:38 -0400 Subject: [PATCH 03/70] chore: dependencias adicionadas --- package-lock.json | 876 +++++++++++++++++++++++++++++++++++++++++++--- package.json | 10 + 2 files changed, 846 insertions(+), 40 deletions(-) diff --git a/package-lock.json b/package-lock.json index ef1eb3d..9ceaaee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,24 +9,34 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "bcrypt": "^5.1.1", "cors": "^2.8.5", + "dotenv": "^16.4.5", "express": "^4.19.2", "helmet": "^7.1.0", + "jsonwebtoken": "^9.0.2", "pg": "^8.12.0" }, "devDependencies": { "@commitlint/config-angular": "^19.3.0", "@commitlint/config-conventional": "^19.2.2", + "@eslint/js": "^9.9.0", "@semantic-release/changelog": "^6.0.3", "@semantic-release/git": "^10.0.1", "@semantic-release/npm": "^12.0.1", "@semantic-release/release-notes-generator": "^14.0.1", + "@types/bcrypt": "^5.0.2", "@types/cors": "^2.8.17", "@types/express": "^4.17.21", + "@types/jest": "^29.5.12", + "@types/jsonwebtoken": "^9.0.6", + "@types/supertest": "^6.0.2", "commitlint": "^19.3.0", + "globals": "^15.9.0", "husky": "^9.1.4", "jest": "^29.7.0", "semantic-release": "^24.0.0", + "supertest": "^7.0.0", "typescript": "^5.5.4" } }, @@ -587,6 +597,16 @@ } } }, + "node_modules/@babel/traverse/node_modules/globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/traverse/node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -1329,6 +1349,16 @@ "node": ">=v18" } }, + "node_modules/@eslint/js": { + "version": "9.9.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.9.0.tgz", + "integrity": "sha512-hhetes6ZHP3BlXLxmd8K2SNgkhNSi+UcecbnwWKwpP7kyi/uC75DJ1lOOBO3xrC4jyojtGE3YxKZPHfk4yrgug==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -1924,6 +1954,98 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@mapbox/node-pre-gyp": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.11.tgz", + "integrity": "sha512-Yhlar6v9WQgUp/He7BdgzOz8lqMQ8sU+jkCq7Wx8Myc5YFJLbEe7lgui/V7G1qB1DJykHSGwreceSaD60Y0PUQ==", + "license": "BSD-3-Clause", + "dependencies": { + "detect-libc": "^2.0.0", + "https-proxy-agent": "^5.0.0", + "make-dir": "^3.1.0", + "node-fetch": "^2.6.7", + "nopt": "^5.0.0", + "npmlog": "^5.0.1", + "rimraf": "^3.0.2", + "semver": "^7.3.5", + "tar": "^6.1.11" + }, + "bin": { + "node-pre-gyp": "bin/node-pre-gyp" + } + }, + "node_modules/@mapbox/node-pre-gyp/node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "license": "MIT", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/@mapbox/node-pre-gyp/node_modules/debug": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", + "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", + "license": "MIT", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/@mapbox/node-pre-gyp/node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "license": "MIT", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/@mapbox/node-pre-gyp/node_modules/make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "license": "MIT", + "dependencies": { + "semver": "^6.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@mapbox/node-pre-gyp/node_modules/make-dir/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/@mapbox/node-pre-gyp/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "license": "MIT" + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -2752,6 +2874,16 @@ "@babel/types": "^7.20.7" } }, + "node_modules/@types/bcrypt": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@types/bcrypt/-/bcrypt-5.0.2.tgz", + "integrity": "sha512-6atioO8Y75fNcbmj0G7UjI9lXN2pQ/IGJ2FWT4a/btd0Lk9lQalHLKhkgKVZ3r+spnmWUKfbMi1GEe9wyHQfNQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/body-parser": { "version": "1.19.5", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.5.tgz", @@ -2780,6 +2912,13 @@ "@types/node": "*" } }, + "node_modules/@types/cookiejar": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.5.tgz", + "integrity": "sha512-he+DHOWReW0nghN24E1WUqM0efK4kI9oTqDm6XmK8ZPe2djZ90BSNdGnIyCLzCPw7/pogPlGbzI2wHGGmi4O/Q==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/cors": { "version": "2.8.17", "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz", @@ -2852,6 +2991,34 @@ "@types/istanbul-lib-report": "*" } }, + "node_modules/@types/jest": { + "version": "29.5.12", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.12.tgz", + "integrity": "sha512-eDC8bTvT/QhYdxJAulQikueigY5AsdBRH2yDKW3yveW7svY3+DzN84/2NUgkw10RTiJbWqZrTtoGVdYlvFJdLw==", + "dev": true, + "license": "MIT", + "dependencies": { + "expect": "^29.0.0", + "pretty-format": "^29.0.0" + } + }, + "node_modules/@types/jsonwebtoken": { + "version": "9.0.6", + "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.6.tgz", + "integrity": "sha512-/5hndP5dCjloafCXns6SZyESp3Ldq7YjH3zwzwczYnjxIT0Fqzk5ROSYVGfFyczIue7IUEj8hkvLbPoLQ18vQw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/methods": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@types/methods/-/methods-1.1.4.tgz", + "integrity": "sha512-ymXWVrDiCxTBE3+RIrrP533E70eA+9qu7zdWoHuOmGujkYtzf4HQF96b8nwHLqhuf4ykX61IGRIB38CC6/sImQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/mime": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz", @@ -2918,6 +3085,30 @@ "integrity": "sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==", "dev": true }, + "node_modules/@types/superagent": { + "version": "8.1.8", + "resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-8.1.8.tgz", + "integrity": "sha512-nTqHJ2OTa7PFEpLahzSEEeFeqbMpmcN7OeayiOc7v+xk+/vyTKljRe+o4MPqSnPeRCMvtxuLG+5QqluUVQJOnA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/cookiejar": "^2.1.5", + "@types/methods": "^1.1.4", + "@types/node": "*", + "form-data": "^4.0.0" + } + }, + "node_modules/@types/supertest": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/@types/supertest/-/supertest-6.0.2.tgz", + "integrity": "sha512-137ypx2lk/wTQbW6An6safu9hXmajAifU/s7szAHLN/FeIm5w7yR0Wkl9fdJMRSHwOn4HLAI0DaB2TOORuhPDg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/methods": "^1.1.4", + "@types/superagent": "^8.1.0" + } + }, "node_modules/@types/yargs": { "version": "17.0.32", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", @@ -2933,6 +3124,12 @@ "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==", "dev": true }, + "node_modules/abbrev": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", + "license": "ISC" + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -3028,7 +3225,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, "engines": { "node": ">=8" } @@ -3067,6 +3263,40 @@ "node": ">= 8" } }, + "node_modules/aproba": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz", + "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==", + "license": "ISC" + }, + "node_modules/are-we-there-yet": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz", + "integrity": "sha512-Ci/qENmwHnsYo9xKIcUJN5LeDKdJ6R1Z1j9V/J5wyq8nh/mYPEpIKJbBZXtZjG04HiK7zV/p6Vs9952MrMeUIw==", + "deprecated": "This package is no longer supported.", + "license": "ISC", + "dependencies": { + "delegates": "^1.0.0", + "readable-stream": "^3.6.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/are-we-there-yet/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "license": "MIT", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -3090,6 +3320,20 @@ "integrity": "sha512-c5AMf34bKdvPhQ7tBGhqkgKNUzMr4WUs+WDtC2ZUGOUncbxKMTvqxYctiseW3+L4bA8ec+GcZ6/A/FW4m8ukng==", "dev": true }, + "node_modules/asap": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", + "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==", + "dev": true, + "license": "MIT" + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true, + "license": "MIT" + }, "node_modules/babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -3234,8 +3478,21 @@ "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "node_modules/bcrypt": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/bcrypt/-/bcrypt-5.1.1.tgz", + "integrity": "sha512-AGBHOG5hPYZ5Xl9KXzU5iKq9516yEmvCKDg3ecP5kX2aB6UqTeXZxk2ELnDgDm6BQSMlLt9rDB4LoSMx0rYwww==", + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "@mapbox/node-pre-gyp": "^1.0.11", + "node-addon-api": "^5.0.0" + }, + "engines": { + "node": ">= 10.0.0" + } }, "node_modules/before-after-hook": { "version": "3.0.2", @@ -3276,7 +3533,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3335,6 +3591,12 @@ "node-int64": "^0.4.0" } }, + "node_modules/buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==", + "license": "BSD-3-Clause" + }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -3426,6 +3688,15 @@ "node": ">=10" } }, + "node_modules/chownr": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", + "license": "ISC", + "engines": { + "node": ">=10" + } + }, "node_modules/ci-info": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", @@ -3594,6 +3865,28 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, + "node_modules/color-support": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", + "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", + "license": "ISC", + "bin": { + "color-support": "bin.js" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commitlint": { "version": "19.3.0", "resolved": "https://registry.npmjs.org/commitlint/-/commitlint-19.3.0.tgz", @@ -3620,11 +3913,20 @@ "dot-prop": "^5.1.0" } }, + "node_modules/component-emitter": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.1.tgz", + "integrity": "sha512-T0+barUSQRTUQASh8bx02dl+DhF54GtIDY13Y3m9oWTklKbb3Wv974meRpeZ3lp1JpLVECWWNHC4vaG2XHXouQ==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", - "dev": true + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, "node_modules/config-chain": { "version": "1.1.13", @@ -3642,6 +3944,12 @@ "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", "dev": true }, + "node_modules/console-control-strings": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==", + "license": "ISC" + }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -3759,6 +4067,13 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" }, + "node_modules/cookiejar": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz", + "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==", + "dev": true, + "license": "MIT" + }, "node_modules/core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", @@ -3966,6 +4281,22 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/delegates": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==", + "license": "MIT" + }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -3983,6 +4314,15 @@ "npm": "1.2.8000 || >= 1.4.16" } }, + "node_modules/detect-libc": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz", + "integrity": "sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw==", + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, "node_modules/detect-newline": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-3.1.0.tgz", @@ -3992,6 +4332,17 @@ "node": ">=8" } }, + "node_modules/dezalgo": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz", + "integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==", + "dev": true, + "license": "ISC", + "dependencies": { + "asap": "^2.0.0", + "wrappy": "1" + } + }, "node_modules/diff-sequences": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", @@ -4025,6 +4376,18 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/duplexer2": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz", @@ -4034,6 +4397,15 @@ "readable-stream": "^2.0.2" } }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "license": "Apache-2.0", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -4060,8 +4432,7 @@ "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, "node_modules/emojilib": { "version": "2.4.0", @@ -4446,6 +4817,13 @@ "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", "dev": true }, + "node_modules/fast-safe-stringify": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==", + "dev": true, + "license": "MIT" + }, "node_modules/fast-uri": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.1.tgz", @@ -4559,6 +4937,36 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/formidable": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-3.5.1.tgz", + "integrity": "sha512-WJWKelbRHN41m5dumb0/k8TeAx7Id/y3a+Z7QfhxP/htI9Js5zYaEDtG8uMgG0vM0lOlqnmjE99/kfpOYi/0Og==", + "dev": true, + "license": "MIT", + "dependencies": { + "dezalgo": "^1.0.4", + "hexoid": "^1.0.0", + "once": "^1.4.0" + }, + "funding": { + "url": "https://ko-fi.com/tunnckoCore/commissions" + } + }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -4591,19 +4999,48 @@ "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", "dev": true, "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=14.14" + } + }, + "node_modules/fs-minipass": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", + "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", + "license": "ISC", + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/fs-minipass/node_modules/minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "license": "ISC", + "dependencies": { + "yallist": "^4.0.0" }, "engines": { - "node": ">=14.14" + "node": ">=8" } }, + "node_modules/fs-minipass/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "license": "ISC" + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", - "dev": true + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, "node_modules/fsevents": { "version": "2.3.3", @@ -4639,6 +5076,27 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/gauge": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz", + "integrity": "sha512-+5J6MS/5XksCuXq++uFRsnUd7Ovu1XenbeuIuNRJxYWjgQbPuFhT14lAvsWfqfAmnwluf1OwMjz39HjfLPci0Q==", + "deprecated": "This package is no longer supported.", + "license": "ISC", + "dependencies": { + "aproba": "^1.0.3 || ^2.0.0", + "color-support": "^1.1.2", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.1", + "object-assign": "^4.1.1", + "signal-exit": "^3.0.0", + "string-width": "^4.2.3", + "strip-ansi": "^6.0.1", + "wide-align": "^1.1.2" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -4753,7 +5211,6 @@ "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", "deprecated": "Glob versions prior to v9 are no longer supported", - "dev": true, "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -4797,12 +5254,16 @@ } }, "node_modules/globals": { - "version": "11.12.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", - "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "version": "15.9.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.9.0.tgz", + "integrity": "sha512-SmSKyLLKFbSr6rptvP8izbyxJL4ILwqO9Jg23UA0sDlGlu58V59D1//I3vlc0KJphVdUR7vMjHIplYnzBxorQA==", "dev": true, + "license": "MIT", "engines": { - "node": ">=4" + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/globby": { @@ -4917,6 +5378,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/has-unicode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==", + "license": "ISC" + }, "node_modules/hasown": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", @@ -4936,6 +5403,16 @@ "node": ">=16.0.0" } }, + "node_modules/hexoid": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz", + "integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/highlight.js": { "version": "10.7.3", "resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.7.3.tgz", @@ -5231,7 +5708,6 @@ "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", - "dev": true, "dependencies": { "once": "^1.3.0", "wrappy": "1" @@ -5309,7 +5785,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, "engines": { "node": ">=8" } @@ -6586,6 +7061,55 @@ "node": "*" } }, + "node_modules/jsonwebtoken": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz", + "integrity": "sha512-PRp66vJ865SSqOlgqS8hujT5U4AOgMfhrwYIuIhfKaoSCZcirrmASQr8CX7cUg+RMih+hgznrjp99o+W4pJLHQ==", + "license": "MIT", + "dependencies": { + "jws": "^3.2.2", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^7.5.4" + }, + "engines": { + "node": ">=12", + "npm": ">=6" + } + }, + "node_modules/jsonwebtoken/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/jwa": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", + "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", + "license": "MIT", + "dependencies": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz", + "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==", + "license": "MIT", + "dependencies": { + "jwa": "^1.4.1", + "safe-buffer": "^5.0.1" + } + }, "node_modules/kleur": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", @@ -6683,17 +7207,39 @@ "integrity": "sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw==", "dev": true }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==", + "license": "MIT" + }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==", + "license": "MIT" + }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==", + "license": "MIT" + }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==", + "license": "MIT" + }, "node_modules/lodash.isplainobject": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", - "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==", - "dev": true + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==" }, "node_modules/lodash.isstring": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", - "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==", - "dev": true + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==" }, "node_modules/lodash.kebabcase": { "version": "4.1.1", @@ -6713,6 +7259,12 @@ "integrity": "sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==", "dev": true }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==", + "license": "MIT" + }, "node_modules/lodash.snakecase": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz", @@ -6909,7 +7461,6 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, "dependencies": { "brace-expansion": "^1.1.7" }, @@ -6926,6 +7477,58 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/minipass": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", + "integrity": "sha512-3FnjYuehv9k6ovOEbyOswadCDPX1piCfhV8ncmYtHOjuPwylVWsghTLo7rabjC3Rx5xD4HDx8Wm1xnMF7S5qFQ==", + "license": "ISC", + "engines": { + "node": ">=8" + } + }, + "node_modules/minizlib": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", + "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", + "license": "MIT", + "dependencies": { + "minipass": "^3.0.0", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/minizlib/node_modules/minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "license": "ISC", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/minizlib/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "license": "ISC" + }, + "node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "license": "MIT", + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -6968,6 +7571,12 @@ "integrity": "sha512-EZSPZB70jiVsivaBLYDCyntd5eH8NTSMOn3rB+HxwdmKThGELLdYv8qVIMWvZEFy9w8ZZpW9h9OB32l1rGtj7g==", "dev": true }, + "node_modules/node-addon-api": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-5.1.0.tgz", + "integrity": "sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA==", + "license": "MIT" + }, "node_modules/node-emoji": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-2.1.3.tgz", @@ -6983,6 +7592,26 @@ "node": ">=18" } }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -6995,6 +7624,21 @@ "integrity": "sha512-d9VeXT4SJ7ZeOqGX6R5EM022wpL+eWPooLI+5UpWn2jCT1aosUQEhQP214x33Wkwx3JQMvIm+tIoVOdodFS40g==", "dev": true }, + "node_modules/nopt": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", + "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", + "license": "ISC", + "dependencies": { + "abbrev": "1" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/normalize-package-data": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-6.0.2.tgz", @@ -9601,6 +10245,19 @@ "inBundle": true, "license": "ISC" }, + "node_modules/npmlog": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz", + "integrity": "sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==", + "deprecated": "This package is no longer supported.", + "license": "ISC", + "dependencies": { + "are-we-there-yet": "^2.0.0", + "console-control-strings": "^1.1.0", + "gauge": "^3.0.0", + "set-blocking": "^2.0.0" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -9635,7 +10292,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "dev": true, "dependencies": { "wrappy": "1" } @@ -9835,7 +10491,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -10512,6 +11167,22 @@ "node": ">=0.10.0" } }, + "node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "deprecated": "Rimraf versions prior to v4 are no longer supported", + "license": "ISC", + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -10843,7 +11514,6 @@ "version": "7.6.3", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", - "dev": true, "bin": { "semver": "bin/semver.js" }, @@ -10920,6 +11590,12 @@ "node": ">= 0.8.0" } }, + "node_modules/set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", + "license": "ISC" + }, "node_modules/set-function-length": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", @@ -10982,8 +11658,7 @@ "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", - "dev": true + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" }, "node_modules/signale": { "version": "1.4.0", @@ -11217,7 +11892,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, "dependencies": { "safe-buffer": "~5.1.0" } @@ -11225,8 +11899,7 @@ "node_modules/string_decoder/node_modules/safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, "node_modules/string-length": { "version": "4.0.2", @@ -11245,7 +11918,6 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -11259,7 +11931,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -11310,6 +11981,79 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/superagent": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-9.0.2.tgz", + "integrity": "sha512-xuW7dzkUpcJq7QnhOsnNUgtYp3xRwpt2F7abdRYIpCsAt0hhUqia0EdxyXZQQpNmGtsCzYHryaKSV3q3GJnq7w==", + "dev": true, + "license": "MIT", + "dependencies": { + "component-emitter": "^1.3.0", + "cookiejar": "^2.1.4", + "debug": "^4.3.4", + "fast-safe-stringify": "^2.1.1", + "form-data": "^4.0.0", + "formidable": "^3.5.1", + "methods": "^1.1.2", + "mime": "2.6.0", + "qs": "^6.11.0" + }, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/superagent/node_modules/debug": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", + "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/superagent/node_modules/mime": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", + "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", + "dev": true, + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/superagent/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true, + "license": "MIT" + }, + "node_modules/supertest": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/supertest/-/supertest-7.0.0.tgz", + "integrity": "sha512-qlsr7fIC0lSddmA3tzojvzubYxvlGtzumcdHgPwbFWMISQwL22MhM2Y3LNt+6w9Yyx7559VW5ab70dgphm8qQA==", + "dev": true, + "license": "MIT", + "dependencies": { + "methods": "^1.1.2", + "superagent": "^9.0.1" + }, + "engines": { + "node": ">=14.18.0" + } + }, "node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -11347,6 +12091,29 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/tar": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.2.1.tgz", + "integrity": "sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==", + "license": "ISC", + "dependencies": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^5.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/tar/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "license": "ISC" + }, "node_modules/temp-dir": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-3.0.0.tgz", @@ -11511,6 +12278,12 @@ "node": ">=0.6" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" + }, "node_modules/traverse": { "version": "0.6.8", "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.6.8.tgz", @@ -11689,8 +12462,7 @@ "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", - "dev": true + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, "node_modules/utils-merge": { "version": "1.0.1", @@ -11741,6 +12513,22 @@ "makeerror": "1.0.12" } }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -11756,6 +12544,15 @@ "node": ">= 8" } }, + "node_modules/wide-align": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", + "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==", + "license": "ISC", + "dependencies": { + "string-width": "^1.0.2 || 2 || 3 || 4" + } + }, "node_modules/wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", @@ -11782,8 +12579,7 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "dev": true + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, "node_modules/write-file-atomic": { "version": "4.0.2", diff --git a/package.json b/package.json index 7c8327b..350bf1a 100644 --- a/package.json +++ b/package.json @@ -20,24 +20,34 @@ "homepage": "https://github.com/TheDevOpsCorp/trainee-backend#readme", "description": "", "dependencies": { + "bcrypt": "^5.1.1", "cors": "^2.8.5", + "dotenv": "^16.4.5", "express": "^4.19.2", "helmet": "^7.1.0", + "jsonwebtoken": "^9.0.2", "pg": "^8.12.0" }, "devDependencies": { "@commitlint/config-angular": "^19.3.0", "@commitlint/config-conventional": "^19.2.2", + "@eslint/js": "^9.9.0", "@semantic-release/changelog": "^6.0.3", "@semantic-release/git": "^10.0.1", "@semantic-release/npm": "^12.0.1", "@semantic-release/release-notes-generator": "^14.0.1", + "@types/bcrypt": "^5.0.2", "@types/cors": "^2.8.17", "@types/express": "^4.17.21", + "@types/jest": "^29.5.12", + "@types/jsonwebtoken": "^9.0.6", + "@types/supertest": "^6.0.2", "commitlint": "^19.3.0", + "globals": "^15.9.0", "husky": "^9.1.4", "jest": "^29.7.0", "semantic-release": "^24.0.0", + "supertest": "^7.0.0", "typescript": "^5.5.4" } } From 7315b9cdf4f51798a93d22d8716071a7621cf9f6 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Tue, 13 Aug 2024 19:55:15 -0400 Subject: [PATCH 04/70] chore: metodo login implementado --- src/controllers/users_controller.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/controllers/users_controller.js diff --git a/src/controllers/users_controller.js b/src/controllers/users_controller.js new file mode 100644 index 0000000..f486597 --- /dev/null +++ b/src/controllers/users_controller.js @@ -0,0 +1,19 @@ +/** + * @typedef {import('express').Request} Request + * @typedef {import('express').Response} Response + */ + +export default { + /** + * @param {Request} req + * @param {Response} res + * */ + async login(req, res) { + const { password, username } = req.body; + if (!password || !username) { + return res.json({ + error: 'password not provided', + }); + } + }, +}; From 0dddc861a01681a7f9a68f15ee59569ff4c704bb Mon Sep 17 00:00:00 2001 From: ItzTas Date: Tue, 13 Aug 2024 19:58:01 -0400 Subject: [PATCH 05/70] =?UTF-8?q?test:=20come=C3=A7ando=20a=20implementar?= =?UTF-8?q?=20testes=20para=20o=20user=20controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/controllers/users_controller.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/controllers/users_controller.test.js diff --git a/test/controllers/users_controller.test.js b/test/controllers/users_controller.test.js new file mode 100644 index 0000000..665df05 --- /dev/null +++ b/test/controllers/users_controller.test.js @@ -0,0 +1,11 @@ +import supertest from 'supertest'; +import app from '../../src/index.js'; +import { truncateUsersTable } from '../../src/database/trucate.js'; + +beforeEach(async () => { + await truncateUsersTable(); +}); + +afterEach(async () => { + await truncateUsersTable(); +}); From 4937bb5b1f72e6e9dae8e0ab9c19080dc1c9b6a4 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Tue, 13 Aug 2024 19:58:37 -0400 Subject: [PATCH 06/70] =?UTF-8?q?chore:=20come=C3=A7ando=20fun=C3=A7=C3=A3?= =?UTF-8?q?o=20para=20truncar=20users?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/database/trucate.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/database/trucate.js diff --git a/src/database/trucate.js b/src/database/trucate.js new file mode 100644 index 0000000..6090d2c --- /dev/null +++ b/src/database/trucate.js @@ -0,0 +1,12 @@ +/** + * @param {String} table + * */ +function truncateTable(table) { + return `TRUNCATE TABLE ${table}`; +} + +async function truncateUsersTable() { + const query = truncateTable('users'); +} + +export { truncateUsersTable }; From 1d92323802c19cba303bb835d86a676e1956ef6a Mon Sep 17 00:00:00 2001 From: Marcelo Cardoso Date: Tue, 13 Aug 2024 23:03:01 -0300 Subject: [PATCH 07/70] chore: adicao nas dependencias --- package-lock.json | 99 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 100 insertions(+) diff --git a/package-lock.json b/package-lock.json index 9ceaaee..d60d31b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,6 +30,7 @@ "@types/express": "^4.17.21", "@types/jest": "^29.5.12", "@types/jsonwebtoken": "^9.0.6", + "@types/pg": "^8.11.6", "@types/supertest": "^6.0.2", "commitlint": "^19.3.0", "globals": "^15.9.0", @@ -3040,6 +3041,80 @@ "integrity": "sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==", "dev": true }, + "node_modules/@types/pg": { + "version": "8.11.6", + "resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.11.6.tgz", + "integrity": "sha512-/2WmmBXHLsfRqzfHW7BNZ8SbYzE8OSk7i3WjFYvfgRHj7S1xj+16Je5fUKv3lVdVzk/zn9TXOqf+avFCFIE0yQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*", + "pg-protocol": "*", + "pg-types": "^4.0.1" + } + }, + "node_modules/@types/pg/node_modules/pg-types": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-4.0.2.tgz", + "integrity": "sha512-cRL3JpS3lKMGsKaWndugWQoLOCoP+Cic8oseVcbr0qhPzYD5DWXK+RZ9LY9wxRf7RQia4SCwQlXk0q6FCPrVng==", + "dev": true, + "license": "MIT", + "dependencies": { + "pg-int8": "1.0.1", + "pg-numeric": "1.0.2", + "postgres-array": "~3.0.1", + "postgres-bytea": "~3.0.0", + "postgres-date": "~2.1.0", + "postgres-interval": "^3.0.0", + "postgres-range": "^1.1.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@types/pg/node_modules/postgres-array": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-3.0.2.tgz", + "integrity": "sha512-6faShkdFugNQCLwucjPcY5ARoW1SlbnrZjmGl0IrrqewpvxvhSLHimCVzqeuULCbG0fQv7Dtk1yDbG3xv7Veog==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/@types/pg/node_modules/postgres-bytea": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-3.0.0.tgz", + "integrity": "sha512-CNd4jim9RFPkObHSjVHlVrxoVQXz7quwNFpz7RY1okNNme49+sVyiTvTRobiLV548Hx/hb1BG+iE7h9493WzFw==", + "dev": true, + "license": "MIT", + "dependencies": { + "obuf": "~1.1.2" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/@types/pg/node_modules/postgres-date": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-2.1.0.tgz", + "integrity": "sha512-K7Juri8gtgXVcDfZttFKVmhglp7epKb1K4pgrkLxehjqkrgPhfG6OO8LHLkfaqkbpjNRnra018XwAr1yQFWGcA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/@types/pg/node_modules/postgres-interval": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-3.0.0.tgz", + "integrity": "sha512-BSNDnbyZCXSxgA+1f5UU2GmwhoI0aU5yMxRGO8CdFEcY2BQF9xm/7MqKnYoM1nJDk8nONNWDk9WeSmePFhQdlw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, "node_modules/@types/qs": { "version": "6.9.15", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.15.tgz", @@ -10277,6 +10352,13 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/obuf": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/obuf/-/obuf-1.1.2.tgz", + "integrity": "sha512-PX1wu0AmAdPqOL1mWhqmlOd8kOIZQwGZw6rh7uby9fTc5lhaOWFLX3I6R1hrF9k3zUY40e6igsLGkDXK92LJNg==", + "dev": true, + "license": "MIT" + }, "node_modules/on-finished": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", @@ -10569,6 +10651,16 @@ "node": ">=4.0.0" } }, + "node_modules/pg-numeric": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/pg-numeric/-/pg-numeric-1.0.2.tgz", + "integrity": "sha512-BM/Thnrw5jm2kKLE5uJkXqqExRUY/toLHda65XgFTBTFYZyopbKjBe29Ii3RbkvlsMoFwD+tHeGaCjjv0gHlyw==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=4" + } + }, "node_modules/pg-pool": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.6.2.tgz", @@ -10829,6 +10921,13 @@ "node": ">=0.10.0" } }, + "node_modules/postgres-range": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/postgres-range/-/postgres-range-1.1.4.tgz", + "integrity": "sha512-i/hbxIE9803Alj/6ytL7UHQxRvZkI9O4Sy+J3HGc4F4oo/2eQAjTSNJ0bfxyse3bH0nuVesCk+3IRLaMtG3H6w==", + "dev": true, + "license": "MIT" + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", diff --git a/package.json b/package.json index 350bf1a..7c7e826 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "@types/express": "^4.17.21", "@types/jest": "^29.5.12", "@types/jsonwebtoken": "^9.0.6", + "@types/pg": "^8.11.6", "@types/supertest": "^6.0.2", "commitlint": "^19.3.0", "globals": "^15.9.0", From 3a72391c7f5ac566770e5353746fa98086174bd0 Mon Sep 17 00:00:00 2001 From: Marcelo Cardoso Date: Tue, 13 Aug 2024 23:12:52 -0300 Subject: [PATCH 08/70] chore: configuracao do database --- src/database/databse.js | 16 ++++++++++++++++ src/database/trucate.js | 4 ++++ 2 files changed, 20 insertions(+) create mode 100644 src/database/databse.js diff --git a/src/database/databse.js b/src/database/databse.js new file mode 100644 index 0000000..f40a05f --- /dev/null +++ b/src/database/databse.js @@ -0,0 +1,16 @@ +import pg from 'pg' + +const {Pool} = pg + +//@ts-ignore +const poolConfig = { + user: process.env["POSTGRES_USER"], + password: process.env["POSTGRES_PASSWORD"], + host: process.env["POSTGRES_HOST"], + port: process.env["POSTGRES_PORT"], + database: process.env["POSTGRES_DATABASE"] +} +//@ts-ignore +const pool = new Pool(poolConfig) + +export {pool} diff --git a/src/database/trucate.js b/src/database/trucate.js index 6090d2c..380eae8 100644 --- a/src/database/trucate.js +++ b/src/database/trucate.js @@ -1,3 +1,5 @@ +import { pool } from "./databse.js"; + /** * @param {String} table * */ @@ -7,6 +9,8 @@ function truncateTable(table) { async function truncateUsersTable() { const query = truncateTable('users'); + + await pool.query(query) } export { truncateUsersTable }; From 988b0272e0b7514c32e8366ccecf371a3a09f631 Mon Sep 17 00:00:00 2001 From: Marcelo Cardoso Date: Tue, 13 Aug 2024 23:14:57 -0300 Subject: [PATCH 09/70] test: configuracao do teste de login --- test/controllers/users_controller.test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/controllers/users_controller.test.js b/test/controllers/users_controller.test.js index 665df05..31f6f1b 100644 --- a/test/controllers/users_controller.test.js +++ b/test/controllers/users_controller.test.js @@ -9,3 +9,25 @@ beforeEach(async () => { afterEach(async () => { await truncateUsersTable(); }); + +describe ("POST /usuario/login login", ()=>{ + + it('Status 200: A rota deve verificar os dados e liberar o acesso', async ()=>{ + + const body = { + user_name: 'tales', + password: '123' + } + + await supertest(app) + .post('/post') + .send(body) + .expect((res)=>{ + + + + }) + + }) + +}) From 0d927a8a3b42b178a93e9c9fee19761a58d09235 Mon Sep 17 00:00:00 2001 From: Marcelo Cardoso Date: Tue, 13 Aug 2024 23:15:25 -0300 Subject: [PATCH 10/70] chore: configuracao de rota --- src/controllers/users_controller.js | 3 +++ src/routes/routes.js | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/controllers/users_controller.js b/src/controllers/users_controller.js index f486597..b707fa4 100644 --- a/src/controllers/users_controller.js +++ b/src/controllers/users_controller.js @@ -8,8 +8,11 @@ export default { * @param {Request} req * @param {Response} res * */ + async login(req, res) { + const { password, username } = req.body; + if (!password || !username) { return res.json({ error: 'password not provided', diff --git a/src/routes/routes.js b/src/routes/routes.js index a9ffe6c..a5b62cc 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -1,7 +1,9 @@ import { Router } from "express"; +import users_controller from "../controllers/users_controller.js"; -const router = Router() +const router = Router() +router.post('/usuario/login', users_controller.login) export default router \ No newline at end of file From 2143d3fe2551641386756f979baec00729e21c0e Mon Sep 17 00:00:00 2001 From: ItzTas Date: Tue, 13 Aug 2024 22:20:39 -0400 Subject: [PATCH 11/70] chore: nome consertado --- src/database/database.js | 16 ++++++++++++++++ src/database/databse.js | 16 ---------------- 2 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 src/database/database.js delete mode 100644 src/database/databse.js diff --git a/src/database/database.js b/src/database/database.js new file mode 100644 index 0000000..a66c898 --- /dev/null +++ b/src/database/database.js @@ -0,0 +1,16 @@ +import pg from 'pg'; + +const { Pool } = pg; + +//@ts-ignore +const poolConfig = { + user: process.env['POSTGRES_USER'], + password: process.env['POSTGRES_PASSWORD'], + host: process.env['POSTGRES_HOST'], + port: process.env['POSTGRES_PORT'], + database: process.env['POSTGRES_DATABASE'], +}; +//@ts-ignore +const pool = new Pool(poolConfig); + +export { pool }; diff --git a/src/database/databse.js b/src/database/databse.js deleted file mode 100644 index f40a05f..0000000 --- a/src/database/databse.js +++ /dev/null @@ -1,16 +0,0 @@ -import pg from 'pg' - -const {Pool} = pg - -//@ts-ignore -const poolConfig = { - user: process.env["POSTGRES_USER"], - password: process.env["POSTGRES_PASSWORD"], - host: process.env["POSTGRES_HOST"], - port: process.env["POSTGRES_PORT"], - database: process.env["POSTGRES_DATABASE"] -} -//@ts-ignore -const pool = new Pool(poolConfig) - -export {pool} From 4d906660b9fa3eeb578ac95bbd8a4ee08568d758 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Tue, 13 Aug 2024 23:17:17 -0400 Subject: [PATCH 12/70] =?UTF-8?q?chore:=20compare=20password=20from=20hash?= =?UTF-8?q?=20fun=C3=A7=C3=A3o=20holder=20implementada?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auth/auth.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/auth/auth.js b/src/auth/auth.js index 40b3eb5..57d7f1c 100644 --- a/src/auth/auth.js +++ b/src/auth/auth.js @@ -11,10 +11,18 @@ const JWT_SECRET = `${process.env['JWT_SECRET']}`; * @returns {String} */ function signJWT(payload, options = {}) { - options.expiresIn = options.expiresIn || dafaultExpirationDate; - options.subject = payload.id; - payload.iat = Math.floor(Date.now() / 1000) - 30; - return jwt.sign(payload, JWT_SECRET, options); + options.expiresIn = options.expiresIn || dafaultExpirationDate; + options.subject = payload.id; + payload.iat = Math.floor(Date.now() / 1000) - 30; + return jwt.sign(payload, JWT_SECRET, options); } -export { signJWT }; +/** + * @param {String} hash + * @param {String} password + * */ +function comparePasswordFromHash(password, hash) { + return password === hash; +} + +export { signJWT, comparePasswordFromHash }; From fb2d691bf6e6c52c3f51b856b6b99b32c97f1316 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Tue, 13 Aug 2024 23:18:17 -0400 Subject: [PATCH 13/70] chore: nome corrigido --- src/database/trucate.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/database/trucate.js b/src/database/trucate.js index 380eae8..5679c6f 100644 --- a/src/database/trucate.js +++ b/src/database/trucate.js @@ -1,4 +1,4 @@ -import { pool } from "./databse.js"; +import { pool } from './database.js'; /** * @param {String} table @@ -9,8 +9,8 @@ function truncateTable(table) { async function truncateUsersTable() { const query = truncateTable('users'); - - await pool.query(query) + + await pool.query(query); } export { truncateUsersTable }; From d438a5186161e32a8827742d575eb5f96306e489 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Tue, 13 Aug 2024 23:18:41 -0400 Subject: [PATCH 14/70] =?UTF-8?q?test:=20implementa=C3=A7=C3=A3o=20do=20te?= =?UTF-8?q?ste=20para=20rota=20login?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/controllers/users_controller.test.js | 47 ++++++++++++++--------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/test/controllers/users_controller.test.js b/test/controllers/users_controller.test.js index 31f6f1b..77bbd8d 100644 --- a/test/controllers/users_controller.test.js +++ b/test/controllers/users_controller.test.js @@ -1,6 +1,7 @@ import supertest from 'supertest'; import app from '../../src/index.js'; import { truncateUsersTable } from '../../src/database/trucate.js'; +import { pool } from '../../src/database/database.js'; beforeEach(async () => { await truncateUsersTable(); @@ -10,24 +11,34 @@ afterEach(async () => { await truncateUsersTable(); }); -describe ("POST /usuario/login login", ()=>{ - - it('Status 200: A rota deve verificar os dados e liberar o acesso', async ()=>{ - +describe('POST /usuario/login login', () => { + it('Status 200: A rota deve verificar os dados e liberar o acesso', async () => { const body = { user_name: 'tales', - password: '123' - } - + password: '123', + }; + + await pool.query( + ` + INSERT INTO users (user_name, password) + VALUES ($1, $2); + `, + [body.user_name, body.password] + ); await supertest(app) - .post('/post') - .send(body) - .expect((res)=>{ - - - - }) - - }) - -}) + .post('/usuario/login') + .send(body) + .expect((res) => { + const { body, status } = res; + try { + expect(status).toBe(200); + } catch (err) { + throw new Error(` + erro: \n${err}\n + body: \n${body}\n + status: \n${status}\n + `); + } + }); + }); +}); From 5e7aa7998773dd533fb0763218e9a8592c4e842a Mon Sep 17 00:00:00 2001 From: ItzTas Date: Tue, 13 Aug 2024 23:19:19 -0400 Subject: [PATCH 15/70] chore: get user by user name implementado --- src/database/users_queries.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/database/users_queries.js diff --git a/src/database/users_queries.js b/src/database/users_queries.js new file mode 100644 index 0000000..4fec9ec --- /dev/null +++ b/src/database/users_queries.js @@ -0,0 +1,22 @@ +import { pool } from './database.js'; + +class ErrorNotFound extends Error { } + +const queryGetUserByUserName = ` + SELECT * FROM USERS + WHERE user_name = $1; +`; + +/** + * @param {String} userName + * @returns {Promise>} + * */ +async function getUsersbyUserName(userName) { + const result = await pool.query(queryGetUserByUserName, [userName]); + if (result.rows.length === 0) { + throw new ErrorNotFound('user not found'); + } + return result.rows[0]; +} + +export { getUsersbyUserName, ErrorNotFound }; From a6d176936246a02df2a3b8721e3b092a3b3d566c Mon Sep 17 00:00:00 2001 From: ItzTas Date: Tue, 13 Aug 2024 23:20:16 -0400 Subject: [PATCH 16/70] =?UTF-8?q?chore:=20methodo=20de=20login=20come?= =?UTF-8?q?=C3=A7ado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/users_controller.js | 45 ++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/controllers/users_controller.js b/src/controllers/users_controller.js index b707fa4..67fe054 100644 --- a/src/controllers/users_controller.js +++ b/src/controllers/users_controller.js @@ -3,20 +3,39 @@ * @typedef {import('express').Response} Response */ +import { + ErrorNotFound, + getUsersbyUserName, +} from '../database/users_queries.js'; + export default { - /** - * @param {Request} req - * @param {Response} res - * */ + /** + * @param {Request} req + * @param {Response} res + * */ + + async login(req, res) { + const { password, user_name } = req.body; - async login(req, res) { - - const { password, username } = req.body; + if (!password || !user_name) { + return res.status(400).json({ + error: 'password or user name not provided', + }); + } - if (!password || !username) { - return res.json({ - error: 'password not provided', - }); - } - }, + let user; + try { + user = await getUsersbyUserName(user_name); + } catch (err) { + if (err instanceof ErrorNotFound) { + return res.status(404).json({ + error: 'user with given name does not exist', + }); + } + return res.status(500).json({ + error: 'could not get user', + error_infos: err, + }); + } + }, }; From b2714888828e0bf3dc6b7f44c55ac9289a41776b Mon Sep 17 00:00:00 2001 From: Marcelo Cardoso Date: Thu, 15 Aug 2024 22:08:47 -0300 Subject: [PATCH 17/70] chore: corrigindo erros de console do teste --- docker/postgres/projeto-final-ddl.sql | 11 ++++++----- jest.setup.js | 7 +++++++ package-lock.json | 1 + src/database/database.js | 7 ++++--- src/database/trucate.js | 1 + src/index.js | 2 ++ test/controllers/users_controller.test.js | 16 ++++++++-------- 7 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 jest.setup.js diff --git a/docker/postgres/projeto-final-ddl.sql b/docker/postgres/projeto-final-ddl.sql index 19ac2a6..9b61b24 100644 --- a/docker/postgres/projeto-final-ddl.sql +++ b/docker/postgres/projeto-final-ddl.sql @@ -5,14 +5,14 @@ CREATE TABLE "follows" ( ); CREATE TABLE "users" ( - "id" integer PRIMARY KEY, + "id" serial PRIMARY KEY, "username" varchar NOT NULL, "password" varchar NOT NULL, "created_at" timestamp NOT NULL DEFAULT 'NOW()' ); CREATE TABLE "posts" ( - "id" integer PRIMARY KEY NOT NULL, + "id" serial PRIMARY KEY, "title" varchar NOT NULL, "body" text NOT NULL, "user_id" integer NOT NULL, @@ -21,8 +21,9 @@ CREATE TABLE "posts" ( COMMENT ON COLUMN "posts"."body" IS 'Content of the post'; -ALTER TABLE "posts" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id"); +ALTER TABLE "posts" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE CASCADE; -ALTER TABLE "follows" ADD FOREIGN KEY ("following_user_id") REFERENCES "users" ("id"); +ALTER TABLE "follows" ADD FOREIGN KEY ("following_user_id") REFERENCES "users" ("id") ON DELETE CASCADE; + +ALTER TABLE "follows" ADD FOREIGN KEY ("followed_user_id") REFERENCES "users" ("id") ON DELETE CASCADE; -ALTER TABLE "follows" ADD FOREIGN KEY ("followed_user_id") REFERENCES "users" ("id"); diff --git a/jest.setup.js b/jest.setup.js new file mode 100644 index 0000000..9b81319 --- /dev/null +++ b/jest.setup.js @@ -0,0 +1,7 @@ +import { configDotenv } from "dotenv"; + +configDotenv() + +export default ()=>{ + configDotenv() +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d60d31b..1d42b2f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10610,6 +10610,7 @@ "version": "8.12.0", "resolved": "https://registry.npmjs.org/pg/-/pg-8.12.0.tgz", "integrity": "sha512-A+LHUSnwnxrnL/tZ+OLfqR1SxLN3c/pgDztZ47Rpbsd4jUytsTtwQo/TLPRzPJMp/1pbhYVhH9cuSZLAajNfjQ==", + "license": "MIT", "dependencies": { "pg-connection-string": "^2.6.4", "pg-pool": "^3.6.2", diff --git a/src/database/database.js b/src/database/database.js index a66c898..4c05a6c 100644 --- a/src/database/database.js +++ b/src/database/database.js @@ -4,12 +4,13 @@ const { Pool } = pg; //@ts-ignore const poolConfig = { - user: process.env['POSTGRES_USER'], - password: process.env['POSTGRES_PASSWORD'], + user: 'postgres', + password: 'postgres', host: process.env['POSTGRES_HOST'], port: process.env['POSTGRES_PORT'], - database: process.env['POSTGRES_DATABASE'], + database: process.env['POSTGRES_DATABASE'] }; + //@ts-ignore const pool = new Pool(poolConfig); diff --git a/src/database/trucate.js b/src/database/trucate.js index 5679c6f..49988e9 100644 --- a/src/database/trucate.js +++ b/src/database/trucate.js @@ -3,6 +3,7 @@ import { pool } from './database.js'; /** * @param {String} table * */ + function truncateTable(table) { return `TRUNCATE TABLE ${table}`; } diff --git a/src/index.js b/src/index.js index f6c5942..7644b71 100644 --- a/src/index.js +++ b/src/index.js @@ -22,4 +22,6 @@ app.listen(port, () => { console.log('Servidor ativo em: http://localhost:3000'); }); +console.log(process.env) + export default app; diff --git a/test/controllers/users_controller.test.js b/test/controllers/users_controller.test.js index 77bbd8d..be425f8 100644 --- a/test/controllers/users_controller.test.js +++ b/test/controllers/users_controller.test.js @@ -1,15 +1,15 @@ import supertest from 'supertest'; import app from '../../src/index.js'; -import { truncateUsersTable } from '../../src/database/trucate.js'; +//import { truncateUsersTable } from '../../src/database/trucate.js'; import { pool } from '../../src/database/database.js'; -beforeEach(async () => { - await truncateUsersTable(); -}); +// beforeEach(async () => { +// await truncateUsersTable(); +// }); -afterEach(async () => { - await truncateUsersTable(); -}); +// afterEach(async () => { +// await truncateUsersTable(); +// }); describe('POST /usuario/login login', () => { it('Status 200: A rota deve verificar os dados e liberar o acesso', async () => { @@ -20,7 +20,7 @@ describe('POST /usuario/login login', () => { await pool.query( ` - INSERT INTO users (user_name, password) + INSERT INTO users (username, password) VALUES ($1, $2); `, [body.user_name, body.password] From 8d78ed6626a73b8e165f49d51ec1855fd5ba2322 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Thu, 15 Aug 2024 22:29:55 -0400 Subject: [PATCH 18/70] chore: helpers movidos --- src/helpers/auth/auth.js | 29 +++++++++++++++++++++++++++++ src/helpers/trucate.js | 17 +++++++++++++++++ src/helpers/users_queries.js | 22 ++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 src/helpers/auth/auth.js create mode 100644 src/helpers/trucate.js create mode 100644 src/helpers/users_queries.js diff --git a/src/helpers/auth/auth.js b/src/helpers/auth/auth.js new file mode 100644 index 0000000..179208f --- /dev/null +++ b/src/helpers/auth/auth.js @@ -0,0 +1,29 @@ +import jwt from 'jsonwebtoken'; +import moment from 'moment'; + +const dafaultExpirationDate = '4hr'; + +const JWT_SECRET = `${process.env['JWT_SECRET']}`; + +/** + * + * @param {Object.} payload + * @param {jwt.SignOptions} [options={ expiresIn: defaultTokenExpiration }] + * @returns {String} + */ +function signJWT(payload, options = {}) { + options.expiresIn = options.expiresIn || dafaultExpirationDate; + options.subject = `${payload.id}`; + payload.iat = moment().unix(); + return jwt.sign(payload, JWT_SECRET, options); +} + +/** + * @param {String} hash + * @param {String} password + * */ +function comparePasswordFromHash(password, hash) { + return password === hash; +} + +export { signJWT, comparePasswordFromHash }; diff --git a/src/helpers/trucate.js b/src/helpers/trucate.js new file mode 100644 index 0000000..49988e9 --- /dev/null +++ b/src/helpers/trucate.js @@ -0,0 +1,17 @@ +import { pool } from './database.js'; + +/** + * @param {String} table + * */ + +function truncateTable(table) { + return `TRUNCATE TABLE ${table}`; +} + +async function truncateUsersTable() { + const query = truncateTable('users'); + + await pool.query(query); +} + +export { truncateUsersTable }; diff --git a/src/helpers/users_queries.js b/src/helpers/users_queries.js new file mode 100644 index 0000000..c2c694a --- /dev/null +++ b/src/helpers/users_queries.js @@ -0,0 +1,22 @@ +import { pool } from '../database/database.js'; + +class ErrorNotFound extends Error {} + +const queryGetUserByUserName = ` + SELECT * FROM "users" + WHERE username = $1; +`; + +/** + * @param {String} userName + * @returns {Promise>} + * */ +async function getUsersbyUserName(userName) { + const result = await pool.query(queryGetUserByUserName, [userName]); + if (result.rows.length === 0) { + throw new ErrorNotFound('user not found'); + } + return result.rows[0]; +} + +export { getUsersbyUserName, ErrorNotFound }; From 5bdbcdb858122841520aacbec4f0c0bd78d3ded9 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Thu, 15 Aug 2024 22:32:38 -0400 Subject: [PATCH 19/70] chore: format object helper --- src/helpers/general_helpers.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/helpers/general_helpers.js diff --git a/src/helpers/general_helpers.js b/src/helpers/general_helpers.js new file mode 100644 index 0000000..5dd2ca0 --- /dev/null +++ b/src/helpers/general_helpers.js @@ -0,0 +1,9 @@ +/** + * + * @param {String} obj - + */ +function formatObject(obj) { + return JSON.stringify(obj, null, 2); +} + +export { formatObject }; From 9c5e514657d5cfec8ca23ccc7c62f845cffcb407 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Thu, 15 Aug 2024 22:34:17 -0400 Subject: [PATCH 20/70] chore: moved --- src/auth/auth.js | 28 ---------------------------- src/database/trucate.js | 17 ----------------- src/database/users_queries.js | 22 ---------------------- 3 files changed, 67 deletions(-) delete mode 100644 src/auth/auth.js delete mode 100644 src/database/trucate.js delete mode 100644 src/database/users_queries.js diff --git a/src/auth/auth.js b/src/auth/auth.js deleted file mode 100644 index 57d7f1c..0000000 --- a/src/auth/auth.js +++ /dev/null @@ -1,28 +0,0 @@ -import jwt from 'jsonwebtoken'; - -const dafaultExpirationDate = '4hr'; - -const JWT_SECRET = `${process.env['JWT_SECRET']}`; - -/** - * - * @param {Object.} payload - * @param {jwt.SignOptions} [options={ expiresIn: defaultTokenExpiration }] - * @returns {String} - */ -function signJWT(payload, options = {}) { - options.expiresIn = options.expiresIn || dafaultExpirationDate; - options.subject = payload.id; - payload.iat = Math.floor(Date.now() / 1000) - 30; - return jwt.sign(payload, JWT_SECRET, options); -} - -/** - * @param {String} hash - * @param {String} password - * */ -function comparePasswordFromHash(password, hash) { - return password === hash; -} - -export { signJWT, comparePasswordFromHash }; diff --git a/src/database/trucate.js b/src/database/trucate.js deleted file mode 100644 index 49988e9..0000000 --- a/src/database/trucate.js +++ /dev/null @@ -1,17 +0,0 @@ -import { pool } from './database.js'; - -/** - * @param {String} table - * */ - -function truncateTable(table) { - return `TRUNCATE TABLE ${table}`; -} - -async function truncateUsersTable() { - const query = truncateTable('users'); - - await pool.query(query); -} - -export { truncateUsersTable }; diff --git a/src/database/users_queries.js b/src/database/users_queries.js deleted file mode 100644 index 4fec9ec..0000000 --- a/src/database/users_queries.js +++ /dev/null @@ -1,22 +0,0 @@ -import { pool } from './database.js'; - -class ErrorNotFound extends Error { } - -const queryGetUserByUserName = ` - SELECT * FROM USERS - WHERE user_name = $1; -`; - -/** - * @param {String} userName - * @returns {Promise>} - * */ -async function getUsersbyUserName(userName) { - const result = await pool.query(queryGetUserByUserName, [userName]); - if (result.rows.length === 0) { - throw new ErrorNotFound('user not found'); - } - return result.rows[0]; -} - -export { getUsersbyUserName, ErrorNotFound }; From b60e2c5147fe074e2eef59d3e6a71000622b3686 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Thu, 15 Aug 2024 22:35:03 -0400 Subject: [PATCH 21/70] chore: moment adicionado --- package-lock.json | 10 ++++++++++ package.json | 1 + 2 files changed, 11 insertions(+) diff --git a/package-lock.json b/package-lock.json index 1d42b2f..9c58d67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "express": "^4.19.2", "helmet": "^7.1.0", "jsonwebtoken": "^9.0.2", + "moment": "^2.30.1", "pg": "^8.12.0" }, "devDependencies": { @@ -7604,6 +7605,15 @@ "node": ">=10" } }, + "node_modules/moment": { + "version": "2.30.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", + "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==", + "license": "MIT", + "engines": { + "node": "*" + } + }, "node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", diff --git a/package.json b/package.json index 7c7e826..d65c8a0 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "express": "^4.19.2", "helmet": "^7.1.0", "jsonwebtoken": "^9.0.2", + "moment": "^2.30.1", "pg": "^8.12.0" }, "devDependencies": { From d771f29f85c02ff778b599035bb95e50f803f451 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Thu, 15 Aug 2024 22:35:38 -0400 Subject: [PATCH 22/70] chore: console log removido --- src/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 7644b71..f18b9fe 100644 --- a/src/index.js +++ b/src/index.js @@ -19,9 +19,7 @@ app.use('/', router); //entrypoint app.listen(port, () => { - console.log('Servidor ativo em: http://localhost:3000'); + console.log('Servidor ativo em: http://localhost:3000'); }); -console.log(process.env) - export default app; From 83ef5beab8e80e86a5496eb565cbc0cb8b7d901b Mon Sep 17 00:00:00 2001 From: ItzTas Date: Thu, 15 Aug 2024 22:36:16 -0400 Subject: [PATCH 23/70] chore: nada mudou --- src/database/database.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/database/database.js b/src/database/database.js index 4c05a6c..6957669 100644 --- a/src/database/database.js +++ b/src/database/database.js @@ -4,11 +4,11 @@ const { Pool } = pg; //@ts-ignore const poolConfig = { - user: 'postgres', - password: 'postgres', - host: process.env['POSTGRES_HOST'], - port: process.env['POSTGRES_PORT'], - database: process.env['POSTGRES_DATABASE'] + user: 'postgres', + password: 'postgres', + host: process.env['POSTGRES_HOST'], + port: process.env['POSTGRES_PORT'], + database: process.env['POSTGRES_DATABASE'], }; //@ts-ignore From 1ad152a169977bbe857e3d87c9ed11f009874a2c Mon Sep 17 00:00:00 2001 From: ItzTas Date: Thu, 15 Aug 2024 22:37:26 -0400 Subject: [PATCH 24/70] feat: login de usuario --- src/controllers/users_controller.js | 70 ++++++++++++++++------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/src/controllers/users_controller.js b/src/controllers/users_controller.js index 67fe054..60f014b 100644 --- a/src/controllers/users_controller.js +++ b/src/controllers/users_controller.js @@ -3,39 +3,49 @@ * @typedef {import('express').Response} Response */ -import { - ErrorNotFound, - getUsersbyUserName, -} from '../database/users_queries.js'; +import { comparePasswordFromHash, signJWT } from '../helpers/auth/auth.js'; +import { ErrorNotFound, getUsersbyUserName } from '../helpers/users_queries.js'; export default { - /** - * @param {Request} req - * @param {Response} res - * */ + /** + * @param {Request} req + * @param {Response} res + * */ - async login(req, res) { - const { password, user_name } = req.body; + async login(req, res) { + const { password, user_name } = req.body; - if (!password || !user_name) { - return res.status(400).json({ - error: 'password or user name not provided', - }); - } + if (!password || !user_name) { + return res.status(400).json({ + error: 'password or user name not provided', + }); + } - let user; - try { - user = await getUsersbyUserName(user_name); - } catch (err) { - if (err instanceof ErrorNotFound) { - return res.status(404).json({ - error: 'user with given name does not exist', - }); - } - return res.status(500).json({ - error: 'could not get user', - error_infos: err, - }); - } - }, + let user; + try { + user = await getUsersbyUserName(user_name); + } catch (err) { + if (err instanceof ErrorNotFound) { + return res.status(404).json({ + error: 'user with given name does not exist', + }); + } + return res.status(500).json({ + error: 'could not get user', + error_infos: err, + }); + } + + if (!comparePasswordFromHash(password, user.password)) { + return res.status(401).json({ + error: 'unauthorized', + }); + } + + const token = signJWT({ id: user.id }); + console.log(token); + return res.status(200).json({ + token: token, + }); + }, }; From 6f5012bad1ab1836bf286ccb095df73ed400fbd8 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Thu, 15 Aug 2024 22:38:09 -0400 Subject: [PATCH 25/70] chore: melhor entendimento de falha de teste --- test/controllers/users_controller.test.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/controllers/users_controller.test.js b/test/controllers/users_controller.test.js index be425f8..b1de47e 100644 --- a/test/controllers/users_controller.test.js +++ b/test/controllers/users_controller.test.js @@ -2,6 +2,7 @@ import supertest from 'supertest'; import app from '../../src/index.js'; //import { truncateUsersTable } from '../../src/database/trucate.js'; import { pool } from '../../src/database/database.js'; +import { formatObject } from '../../src/helpers/general_helpers.js'; // beforeEach(async () => { // await truncateUsersTable(); @@ -20,7 +21,7 @@ describe('POST /usuario/login login', () => { await pool.query( ` - INSERT INTO users (username, password) + INSERT INTO "users" (username, password) VALUES ($1, $2); `, [body.user_name, body.password] @@ -34,9 +35,9 @@ describe('POST /usuario/login login', () => { expect(status).toBe(200); } catch (err) { throw new Error(` - erro: \n${err}\n - body: \n${body}\n + body: \n${formatObject(body)}\n status: \n${status}\n + erro: \n${err}\n `); } }); From ada047276a2bbe0cfb660d341837dd3ea80d6de8 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Thu, 15 Aug 2024 23:05:26 -0400 Subject: [PATCH 26/70] chore: jest setup realmente configurado --- jest.config.mjs | 269 ++++++++++++++-------------- jest.setup.js | 10 +- src/controllers/users_controller.js | 71 ++++---- src/database/database.js | 10 +- 4 files changed, 178 insertions(+), 182 deletions(-) diff --git a/jest.config.mjs b/jest.config.mjs index e3e017e..5717275 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -5,194 +5,191 @@ /** @type {import('jest').Config} */ const config = { - // All imported modules in your tests should be mocked automatically - // automock: false, + // All imported modules in your tests should be mocked automatically + // automock: false, - // Stop running tests after `n` failures - // bail: 0, + // Stop running tests after `n` failures + // bail: 0, - // The directory where Jest should store its cached dependency information - // cacheDirectory: "/tmp/jest_rs", + // The directory where Jest should store its cached dependency information + // cacheDirectory: "/tmp/jest_rs", - // Automatically clear mock calls, instances, contexts and results before every test - clearMocks: true, + // Automatically clear mock calls, instances, contexts and results before every test + clearMocks: true, - // Indicates whether the coverage information should be collected while executing the test - collectCoverage: true, + // Indicates whether the coverage information should be collected while executing the test + collectCoverage: true, - // An array of glob patterns indicating a set of files for which coverage information should be collected - // collectCoverageFrom: undefined, + // An array of glob patterns indicating a set of files for which coverage information should be collected + // collectCoverageFrom: undefined, - // The directory where Jest should output its coverage files - coverageDirectory: "coverage", + // The directory where Jest should output its coverage files + coverageDirectory: 'coverage', - // An array of regexp pattern strings used to skip coverage collection - // coveragePathIgnorePatterns: [ - // "/node_modules/" - // ], + // An array of regexp pattern strings used to skip coverage collection + // coveragePathIgnorePatterns: [ + // "/node_modules/" + // ], - // Indicates which provider should be used to instrument code for coverage - coverageProvider: "v8", + // Indicates which provider should be used to instrument code for coverage + coverageProvider: 'v8', - // A list of reporter names that Jest uses when writing coverage reports - // coverageReporters: [ - // "json", - // "text", - // "lcov", - // "clover" - // ], + // A list of reporter names that Jest uses when writing coverage reports + // coverageReporters: [ + // "json", + // "text", + // "lcov", + // "clover" + // ], - // An object that configures minimum threshold enforcement for coverage results - // coverageThreshold: undefined, + // An object that configures minimum threshold enforcement for coverage results + // coverageThreshold: undefined, - // A path to a custom dependency extractor - // dependencyExtractor: undefined, + // A path to a custom dependency extractor + // dependencyExtractor: undefined, - // Make calling deprecated APIs throw helpful error messages - // errorOnDeprecated: false, + // Make calling deprecated APIs throw helpful error messages + // errorOnDeprecated: false, - // The default configuration for fake timers - // fakeTimers: { - // "enableGlobally": false - // }, + // The default configuration for fake timers + // fakeTimers: { + // "enableGlobally": false + // }, - // Force coverage collection from ignored files using an array of glob patterns - // forceCoverageMatch: [], + // Force coverage collection from ignored files using an array of glob patterns + // forceCoverageMatch: [], - // A path to a module which exports an async function that is triggered once before all test suites - // globalSetup: undefined, + // A path to a module which exports an async function that is triggered once before all test suites + globalSetup: './jest.setup.js', - // A path to a module which exports an async function that is triggered once after all test suites - // globalTeardown: undefined, + // A path to a module which exports an async function that is triggered once after all test suites + // globalTeardown: undefined, - // A set of global variables that need to be available in all test environments - // globals: {}, + // A set of global variables that need to be available in all test environments + // globals: {}, - // The maximum amount of workers used to run your tests. Can be specified as % or a number. 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. - // maxWorkers: "50%", + // The maximum amount of workers used to run your tests. Can be specified as % or a number. 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. + // maxWorkers: "50%", - // An array of directory names to be searched recursively up from the requiring module's location - // moduleDirectories: [ - // "node_modules" - // ], + // An array of directory names to be searched recursively up from the requiring module's location + // moduleDirectories: [ + // "node_modules" + // ], - // An array of file extensions your modules use - // moduleFileExtensions: [ - // "js", - // "mjs", - // "cjs", - // "jsx", - // "ts", - // "tsx", - // "json", - // "node" - // ], + // An array of file extensions your modules use + moduleFileExtensions: [ + 'js', + 'mjs', + 'cjs', + 'jsx', + 'ts', + 'tsx', + 'json', + 'node', + ], - // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module - // moduleNameMapper: {}, + // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module + // moduleNameMapper: {}, - // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader - // modulePathIgnorePatterns: [], + // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader + // modulePathIgnorePatterns: [], - // Activates notifications for test results - // notify: false, + // Activates notifications for test results + // notify: false, - // An enum that specifies notification mode. Requires { notify: true } - // notifyMode: "failure-change", + // An enum that specifies notification mode. Requires { notify: true } + // notifyMode: "failure-change", - // A preset that is used as a base for Jest's configuration - // preset: undefined, + // A preset that is used as a base for Jest's configuration + // preset: undefined, - // Run tests from one or more projects - // projects: undefined, + // Run tests from one or more projects + // projects: undefined, - // Use this configuration option to add custom reporters to Jest - // reporters: undefined, + // Use this configuration option to add custom reporters to Jest + // reporters: undefined, - // Automatically reset mock state before every test - // resetMocks: false, + // Automatically reset mock state before every test + // resetMocks: false, - // Reset the module registry before running each individual test - // resetModules: false, + // Reset the module registry before running each individual test + // resetModules: false, - // A path to a custom resolver - // resolver: undefined, + // A path to a custom resolver + // resolver: undefined, - // Automatically restore mock state and implementation before every test - // restoreMocks: false, + // Automatically restore mock state and implementation before every test + // restoreMocks: false, - // The root directory that Jest should scan for tests and modules within - // rootDir: undefined, + // The root directory that Jest should scan for tests and modules within + // rootDir: undefined, - // A list of paths to directories that Jest should use to search for files in - // roots: [ - // "" - // ], + // A list of paths to directories that Jest should use to search for files in + // roots: [ + // "" + // ], - // Allows you to use a custom runner instead of Jest's default test runner - // runner: "jest-runner", + // Allows you to use a custom runner instead of Jest's default test runner + // runner: "jest-runner", - // The paths to modules that run some code to configure or set up the testing environment before each test - // setupFiles: [], + // The paths to modules that run some code to configure or set up the testing environment before each test + // setupFiles: ['jest.setup.js'], - // A list of paths to modules that run some code to configure or set up the testing framework before each test - // setupFilesAfterEnv: [], + // A list of paths to modules that run some code to configure or set up the testing framework before each test + // setupFilesAfterEnv: [], - // The number of seconds after which a test is considered as slow and reported as such in the results. - // slowTestThreshold: 5, + // The number of seconds after which a test is considered as slow and reported as such in the results. + // slowTestThreshold: 5, - // A list of paths to snapshot serializer modules Jest should use for snapshot testing - // snapshotSerializers: [], + // A list of paths to snapshot serializer modules Jest should use for snapshot testing + // snapshotSerializers: [], - // The test environment that will be used for testing - // testEnvironment: "jest-environment-node", + // The test environment that will be used for testing + // testEnvironment: "jest-environment-node", - // Options that will be passed to the testEnvironment - // testEnvironmentOptions: {}, + // Options that will be passed to the testEnvironment + // testEnvironmentOptions: {}, - // Adds a location field to test results - // testLocationInResults: false, + // Adds a location field to test results + // testLocationInResults: false, - // The glob patterns Jest uses to detect test files - // testMatch: [ - // "**/__tests__/**/*.[jt]s?(x)", - // "**/?(*.)+(spec|test).[tj]s?(x)" - // ], + // The glob patterns Jest uses to detect test files + testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'], - // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped - // testPathIgnorePatterns: [ - // "/node_modules/" - // ], + // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped + // testPathIgnorePatterns: [ + // "/node_modules/" + // ], - // The regexp pattern or array of patterns that Jest uses to detect test files - // testRegex: [], + // The regexp pattern or array of patterns that Jest uses to detect test files + // testRegex: [], - // This option allows the use of a custom results processor - // testResultsProcessor: undefined, + // This option allows the use of a custom results processor + // testResultsProcessor: undefined, - // This option allows use of a custom test runner - // testRunner: "jest-circus/runner", + // This option allows use of a custom test runner + // testRunner: "jest-circus/runner", - // A map from regular expressions to paths to transformers - // transform: undefined, + // A map from regular expressions to paths to transformers + // transform: undefined, - // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation - // transformIgnorePatterns: [ - // "/node_modules/", - // "\\.pnp\\.[^\\/]+$" - // ], + // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation + // transformIgnorePatterns: [ + // "/node_modules/", + // "\\.pnp\\.[^\\/]+$" + // ], - // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them - // unmockedModulePathPatterns: undefined, + // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them + // unmockedModulePathPatterns: undefined, - // Indicates whether each individual test should be reported during the run - // verbose: undefined, + // Indicates whether each individual test should be reported during the run + // verbose: undefined, - // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode - // watchPathIgnorePatterns: [], + // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode + // watchPathIgnorePatterns: [], - // Whether to use watchman for file crawling - // watchman: true, + // Whether to use watchman for file crawling + // watchman: true, }; export default config; diff --git a/jest.setup.js b/jest.setup.js index 9b81319..a003d96 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -1,7 +1,7 @@ -import { configDotenv } from "dotenv"; +import { configDotenv } from 'dotenv'; -configDotenv() +configDotenv(); -export default ()=>{ - configDotenv() -} \ No newline at end of file +export default () => { + configDotenv(); +}; diff --git a/src/controllers/users_controller.js b/src/controllers/users_controller.js index 60f014b..0284de5 100644 --- a/src/controllers/users_controller.js +++ b/src/controllers/users_controller.js @@ -7,45 +7,44 @@ import { comparePasswordFromHash, signJWT } from '../helpers/auth/auth.js'; import { ErrorNotFound, getUsersbyUserName } from '../helpers/users_queries.js'; export default { - /** - * @param {Request} req - * @param {Response} res - * */ + /** + * @param {Request} req + * @param {Response} res + * */ - async login(req, res) { - const { password, user_name } = req.body; + async login(req, res) { + const { password, user_name } = req.body; - if (!password || !user_name) { - return res.status(400).json({ - error: 'password or user name not provided', - }); - } + if (!password || !user_name) { + return res.status(400).json({ + error: 'password or user name not provided', + }); + } - let user; - try { - user = await getUsersbyUserName(user_name); - } catch (err) { - if (err instanceof ErrorNotFound) { - return res.status(404).json({ - error: 'user with given name does not exist', - }); - } - return res.status(500).json({ - error: 'could not get user', - error_infos: err, - }); - } + let user; + try { + user = await getUsersbyUserName(user_name); + } catch (err) { + if (err instanceof ErrorNotFound) { + return res.status(404).json({ + error: 'user with given name does not exist', + }); + } + return res.status(500).json({ + error: 'could not get user', + error_infos: err, + }); + } - if (!comparePasswordFromHash(password, user.password)) { - return res.status(401).json({ - error: 'unauthorized', - }); - } + if (!comparePasswordFromHash(password, user.password)) { + return res.status(401).json({ + error: 'unauthorized', + }); + } - const token = signJWT({ id: user.id }); - console.log(token); - return res.status(200).json({ - token: token, - }); - }, + const token = signJWT({ id: user.id }); + return res.status(200).json({ + token: token, + }); + }, }; diff --git a/src/database/database.js b/src/database/database.js index 6957669..f405787 100644 --- a/src/database/database.js +++ b/src/database/database.js @@ -4,11 +4,11 @@ const { Pool } = pg; //@ts-ignore const poolConfig = { - user: 'postgres', - password: 'postgres', - host: process.env['POSTGRES_HOST'], - port: process.env['POSTGRES_PORT'], - database: process.env['POSTGRES_DATABASE'], + user: process.env['POSTGRES_USER'], + password: `${process.env['POSTGRES_PASSWORD']}`, + host: process.env['POSTGRES_HOST'], + port: process.env['POSTGRES_PORT'], + database: process.env['POSTGRES_DATABASE'], }; //@ts-ignore From a6d7c8877c2b08d3bfc7e9c866a2df347131e405 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:43:08 -0300 Subject: [PATCH 27/70] ci: adicionando docker compose --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e84c5a..f7deb45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,8 @@ jobs: steps: - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 + - name: Execuntando Docker Compose + uses: hoverkraft-tech/compose-action@v2.0.1 - name: Configurando Node.Js uses: actions/setup-node@v4.0.3 with: From 26fcc7b5a020696569be72caa714612710f7f536 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:47:23 -0300 Subject: [PATCH 28/70] =?UTF-8?q?ci:=20=20aplicando=20configura=C3=A7?= =?UTF-8?q?=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7deb45..5d8719f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,8 @@ jobs: uses: actions/checkout@v4.1.7 - name: Execuntando Docker Compose uses: hoverkraft-tech/compose-action@v2.0.1 + with: + services: database - name: Configurando Node.Js uses: actions/setup-node@v4.0.3 with: From 1bb2d8d56fdff02c6225c2851ba65cd2d2c7e1f7 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:58:53 -0300 Subject: [PATCH 29/70] ci: configurando envs no workflow --- .github/workflows/ci.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d8719f..4c3c8c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,16 +8,26 @@ jobs: steps: - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 + - name: Execuntando Docker Compose uses: hoverkraft-tech/compose-action@v2.0.1 with: services: database + - name: Configurando Node.Js uses: actions/setup-node@v4.0.3 with: node-version: '20' + env: + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_HOST: ${POSTGRES_HOST} + POSTGRES_PORT: ${POSTGRES_PORT} + POSTGRES_DATABASE: ${POSTGRES_DATABASE} + JWT_SECRET: ${JWT_SECRET} + - name: Instalando Dependencias run: npm clean-install + - name: Executando Testes run: npm run test - From 171d617c3a005e4595bc7bf6f592a0ccdc3135b9 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:01:44 -0300 Subject: [PATCH 30/70] ci: atualizando workflow --- .github/workflows/ci.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c3c8c9..e876fd0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,13 @@ jobs: uses: actions/setup-node@v4.0.3 with: node-version: '20' + + + - name: Instalando Dependencias + run: npm clean-install + + - name: Executando Testes + run: npm run test env: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} @@ -25,9 +32,3 @@ jobs: POSTGRES_PORT: ${POSTGRES_PORT} POSTGRES_DATABASE: ${POSTGRES_DATABASE} JWT_SECRET: ${JWT_SECRET} - - - name: Instalando Dependencias - run: npm clean-install - - - name: Executando Testes - run: npm run test From a0a1864e7e73b97941438119c9a12352fa3252f8 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:30:42 -0300 Subject: [PATCH 31/70] ci: ajustando workflow --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e876fd0..b2dd3d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,9 +26,9 @@ jobs: - name: Executando Testes run: npm run test env: - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - POSTGRES_HOST: ${POSTGRES_HOST} - POSTGRES_PORT: ${POSTGRES_PORT} - POSTGRES_DATABASE: ${POSTGRES_DATABASE} - JWT_SECRET: ${JWT_SECRET} + POSTGRES_USER: ${varibles.POSTGRES_USER} + POSTGRES_PASSWORD: ${varibles.POSTGRES_PASSWORD} + POSTGRES_HOST: ${varibles.POSTGRES_HOST} + POSTGRES_PORT: ${varibles.POSTGRES_PORT} + POSTGRES_DATABASE: ${varibles.POSTGRES_DATABASE} + JWT_SECRET: ${secrets.JWT_SECRET} From 47985938a2ddd8d2df05e3dcb8b0ab99fb7a3c43 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:49:07 -0300 Subject: [PATCH 32/70] ci : ajustando workflow --- .github/workflows/ci.yml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2dd3d7..f4cfef5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,11 +1,25 @@ name: Testes Unitarios on: [push, pull_request] - +env: + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + POSTGRES_HOST: ${POSTGRES_HOST} + POSTGRES_PORT: ${POSTGRES_PORT} + POSTGRES_DATABASE: ${POSTGRES_DATABASE} + JWT_SECRET: ${secrets.JWT_SECRET} jobs: CI: runs-on: ubuntu-latest steps: + - name: Verificando Envs + run: | + echo ${POSTGRES_USER} + echo ${POSTGRES_PASSWORD} + echo ${POSTGRES_HOST} + echo ${POSTGRES_PORT} + echo ${POSTGRES_DATABASE} + echo ${secrets.JWT_SECRET} - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 @@ -25,10 +39,4 @@ jobs: - name: Executando Testes run: npm run test - env: - POSTGRES_USER: ${varibles.POSTGRES_USER} - POSTGRES_PASSWORD: ${varibles.POSTGRES_PASSWORD} - POSTGRES_HOST: ${varibles.POSTGRES_HOST} - POSTGRES_PORT: ${varibles.POSTGRES_PORT} - POSTGRES_DATABASE: ${varibles.POSTGRES_DATABASE} - JWT_SECRET: ${secrets.JWT_SECRET} + From 9f0b93aa290b50499af86b4495d445a6c66f11c7 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:51:34 -0300 Subject: [PATCH 33/70] ci: ajustando worflow --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f4cfef5..d5de4e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,12 +14,12 @@ jobs: steps: - name: Verificando Envs run: | - echo ${POSTGRES_USER} - echo ${POSTGRES_PASSWORD} - echo ${POSTGRES_HOST} - echo ${POSTGRES_PORT} - echo ${POSTGRES_DATABASE} - echo ${secrets.JWT_SECRET} + echo "$POSTGRES_USER" + echo "$POSTGRES_PASSWORD" + echo "$POSTGRES_HOST" + echo "$POSTGRES_PORT" + echo "$POSTGRES_DATABASE" + echo "$JWT_SECRET" - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 From 7eb4396ba582d68963e43c081d5108b63b911941 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:55:16 -0300 Subject: [PATCH 34/70] ci: ajustando workflow --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5de4e6..f36a0ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,12 +2,12 @@ name: Testes Unitarios on: [push, pull_request] env: - POSTGRES_USER: ${POSTGRES_USER} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} - POSTGRES_HOST: ${POSTGRES_HOST} - POSTGRES_PORT: ${POSTGRES_PORT} - POSTGRES_DATABASE: ${POSTGRES_DATABASE} - JWT_SECRET: ${secrets.JWT_SECRET} + POSTGRES_USER: ${{env.POSTGRES_USER}} + POSTGRES_PASSWORD: ${{env.POSTGRES_PASSWORD}} + POSTGRES_HOST: ${{env.POSTGRES_HOST}} + POSTGRES_PORT: ${{env.POSTGRES_PORT}} + POSTGRES_DATABASE: ${{env.POSTGRES_DATABASE}} + JWT_SECRET: ${{secrets.JWT_SECRET}} jobs: CI: runs-on: ubuntu-latest From 54ce4955980a5e047dfaf8bc2d35eb15a02e64c2 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:56:42 -0300 Subject: [PATCH 35/70] ci: ajustando workflow --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f36a0ff..9ddb939 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,11 +2,11 @@ name: Testes Unitarios on: [push, pull_request] env: - POSTGRES_USER: ${{env.POSTGRES_USER}} - POSTGRES_PASSWORD: ${{env.POSTGRES_PASSWORD}} - POSTGRES_HOST: ${{env.POSTGRES_HOST}} - POSTGRES_PORT: ${{env.POSTGRES_PORT}} - POSTGRES_DATABASE: ${{env.POSTGRES_DATABASE}} + POSTGRES_USER: ${{var.POSTGRES_USER}} + POSTGRES_PASSWORD: ${{var.POSTGRES_PASSWORD}} + POSTGRES_HOST: ${{var.POSTGRES_HOST}} + POSTGRES_PORT: ${{var.POSTGRES_PORT}} + POSTGRES_DATABASE: ${{var.POSTGRES_DATABASE}} JWT_SECRET: ${{secrets.JWT_SECRET}} jobs: CI: From 206b0b881fd6df3655ff8488c3b83e8282a1f086 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:00:03 -0300 Subject: [PATCH 36/70] ci: ainda ajustando workflow --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ddb939..a56f62f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,11 +2,11 @@ name: Testes Unitarios on: [push, pull_request] env: - POSTGRES_USER: ${{var.POSTGRES_USER}} - POSTGRES_PASSWORD: ${{var.POSTGRES_PASSWORD}} - POSTGRES_HOST: ${{var.POSTGRES_HOST}} - POSTGRES_PORT: ${{var.POSTGRES_PORT}} - POSTGRES_DATABASE: ${{var.POSTGRES_DATABASE}} + POSTGRES_USER: ${{GITHUB_REPOSITORY.POSTGRES_USER}} + POSTGRES_PASSWORD: ${{GITHUB_REPOSITORY.POSTGRES_PASSWORD}} + POSTGRES_HOST: ${{GITHUB_REPOSITORY.POSTGRES_HOST}} + POSTGRES_PORT: ${{GITHUB_REPOSITORY.POSTGRES_PORT}} + POSTGRES_DATABASE: ${{GITHUB_REPOSITORY.POSTGRES_DATABASE}} JWT_SECRET: ${{secrets.JWT_SECRET}} jobs: CI: From 873ce4d1b207220066eea2415582749141f418e5 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:01:52 -0300 Subject: [PATCH 37/70] ci ajustando workflow --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a56f62f..6fd6ff8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,11 +2,11 @@ name: Testes Unitarios on: [push, pull_request] env: - POSTGRES_USER: ${{GITHUB_REPOSITORY.POSTGRES_USER}} - POSTGRES_PASSWORD: ${{GITHUB_REPOSITORY.POSTGRES_PASSWORD}} - POSTGRES_HOST: ${{GITHUB_REPOSITORY.POSTGRES_HOST}} - POSTGRES_PORT: ${{GITHUB_REPOSITORY.POSTGRES_PORT}} - POSTGRES_DATABASE: ${{GITHUB_REPOSITORY.POSTGRES_DATABASE}} + POSTGRES_USER: ${{POSTGRES_USER}} + POSTGRES_PASSWORD: ${{POSTGRES_PASSWORD}} + POSTGRES_HOST: ${{POSTGRES_HOST}} + POSTGRES_PORT: ${{POSTGRES_PORT}} + POSTGRES_DATABASE: ${{POSTGRES_DATABASE}} JWT_SECRET: ${{secrets.JWT_SECRET}} jobs: CI: From 816fe7a2d147089c6f666fff2681647121e377a2 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:06:01 -0300 Subject: [PATCH 38/70] ci: ajustando workflow --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fd6ff8..28d3cd7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,11 +2,11 @@ name: Testes Unitarios on: [push, pull_request] env: - POSTGRES_USER: ${{POSTGRES_USER}} - POSTGRES_PASSWORD: ${{POSTGRES_PASSWORD}} - POSTGRES_HOST: ${{POSTGRES_HOST}} - POSTGRES_PORT: ${{POSTGRES_PORT}} - POSTGRES_DATABASE: ${{POSTGRES_DATABASE}} + POSTGRES_USER: ${{vars.POSTGRES_USER}} + POSTGRES_PASSWORD: ${{vars.POSTGRES_PASSWORD}} + POSTGRES_HOST: ${{vars.POSTGRES_HOST}} + POSTGRES_PORT: ${{vars.POSTGRES_PORT}} + POSTGRES_DATABASE: ${{vars.POSTGRES_DATABASE}} JWT_SECRET: ${{secrets.JWT_SECRET}} jobs: CI: From 520b4d509d459aa995f46779c463d34555ad834d Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:28:41 -0300 Subject: [PATCH 39/70] ci: ajustando worklow --- .github/workflows/ci.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28d3cd7..e4c6675 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,9 +8,20 @@ env: POSTGRES_PORT: ${{vars.POSTGRES_PORT}} POSTGRES_DATABASE: ${{vars.POSTGRES_DATABASE}} JWT_SECRET: ${{secrets.JWT_SECRET}} + + jobs: CI: runs-on: ubuntu-latest + services: + database: + image: postgres:16 + ports: + - 5432:5432 + env: + POSTGRES_USER: $POSTGRES_USER + POSTGRES_PASSWORD: $POSTGRES_PASSWORD + POSTGRES_DB: $POSTGRES_DATABASE steps: - name: Verificando Envs run: | From 8bb61ab50d4767bafb05720f3cf1e34eb215e7dd Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:32:05 -0300 Subject: [PATCH 40/70] ci: ajustando workflow --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4c6675..2e0ed16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,9 @@ jobs: services: database: image: postgres:16 + volumes: + - ./docker/postgres/data:/var/lib/postgresql/data + - ./docker/postgres/projeto-final-ddl.sql:/docker-entrypoint-initdb.d/initdb-projeto-final-ddl.sql ports: - 5432:5432 env: From 97d8b67b7ec30903e3dd87cc41831c8ae0a84d39 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:23:49 -0300 Subject: [PATCH 41/70] ci: ajustando workflow --- .github/workflows/ci.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2e0ed16..c4c4e8e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,20 +34,15 @@ jobs: echo "$POSTGRES_PORT" echo "$POSTGRES_DATABASE" echo "$JWT_SECRET" + - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 - - name: Execuntando Docker Compose - uses: hoverkraft-tech/compose-action@v2.0.1 - with: - services: database - - name: Configurando Node.Js uses: actions/setup-node@v4.0.3 with: node-version: '20' - - name: Instalando Dependencias run: npm clean-install From edbe051e3afb0d963c1702aa8fec4b17b943ed09 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:25:56 -0300 Subject: [PATCH 42/70] ci: ajustando workflow --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c4c4e8e..426098d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,6 @@ jobs: database: image: postgres:16 volumes: - - ./docker/postgres/data:/var/lib/postgresql/data - ./docker/postgres/projeto-final-ddl.sql:/docker-entrypoint-initdb.d/initdb-projeto-final-ddl.sql ports: - 5432:5432 From 03a47f4b506653aa85083256f9693ef5fc4b9743 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Fri, 16 Aug 2024 21:31:18 -0300 Subject: [PATCH 43/70] ci: ajustando workflow --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 426098d..b69a9e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,9 @@ jobs: echo "$POSTGRES_DATABASE" echo "$JWT_SECRET" + - name: Forçar remoção do diretório + run: sudo rm -rf /home/runner/work/projeto-final-trainee-backend/projeto-final-trainee-backend/docker/postgres + - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 From f6fefe457ffc68f4e9cd232753234fae849ef4aa Mon Sep 17 00:00:00 2001 From: Marcelo Cardoso Date: Fri, 16 Aug 2024 23:18:07 -0300 Subject: [PATCH 44/70] test: erro 400 sem nome sem senha --- test/controllers/users_controller.test.js | 94 +++++++++++++++-------- 1 file changed, 64 insertions(+), 30 deletions(-) diff --git a/test/controllers/users_controller.test.js b/test/controllers/users_controller.test.js index b1de47e..e6544ce 100644 --- a/test/controllers/users_controller.test.js +++ b/test/controllers/users_controller.test.js @@ -1,8 +1,8 @@ -import supertest from 'supertest'; -import app from '../../src/index.js'; +import supertest from "supertest"; +import app from "../../src/index.js"; //import { truncateUsersTable } from '../../src/database/trucate.js'; -import { pool } from '../../src/database/database.js'; -import { formatObject } from '../../src/helpers/general_helpers.js'; +import { pool } from "../../src/database/database.js"; +import { formatObject } from "../../src/helpers/general_helpers.js"; // beforeEach(async () => { // await truncateUsersTable(); @@ -12,34 +12,68 @@ import { formatObject } from '../../src/helpers/general_helpers.js'; // await truncateUsersTable(); // }); -describe('POST /usuario/login login', () => { - it('Status 200: A rota deve verificar os dados e liberar o acesso', async () => { - const body = { - user_name: 'tales', - password: '123', - }; +describe("POST /usuario/login login", () => { + it("Status 200: A rota deve verificar os dados e liberar o acesso", async () => { + const body = { + user_name: "tales", + password: "123", + }; - await pool.query( - ` + await pool.query( + ` INSERT INTO "users" (username, password) VALUES ($1, $2); `, - [body.user_name, body.password] - ); - await supertest(app) - .post('/usuario/login') - .send(body) - .expect((res) => { - const { body, status } = res; - try { - expect(status).toBe(200); - } catch (err) { - throw new Error(` - body: \n${formatObject(body)}\n - status: \n${status}\n - erro: \n${err}\n - `); - } - }); - }); + [body.user_name, body.password] + ); + await supertest(app) + .post("/usuario/login") + .send(body) + .expect((res) => { + const { body, status } = res; + try { + expect(status).toBe(200); + } catch (err) { + throw new Error(` + body: \n${formatObject(body)}\n + status: \n${status}\n + error: \n${err}\n + `); + } + }); + }); + + it("Status 400: Deve dar erro se o body estiver incompleto", async () => { + const testes = [ + { + teste_name: "semSenha", + user_name: "tales", + }, + { + teste_name: "semNome", + password: "123", + }, + ]; + + await supertest(app) + .post("/usuario/login") + .send(testes) + .expect((res) => { + const { body, status } = res; + + try { + expect(status).toBe(400); + expect(body).toHaveProperty( + "error", + "password or user name not provided" + ); + } catch (error) { + throw new Error(` + body: \n${formatObject(body)}\n + status: \n${status}\n + error: \n${error}\n + `); + } + }); + }); }); From b4929e58790e3508496045809f13d091fca07c43 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Fri, 16 Aug 2024 23:05:16 -0400 Subject: [PATCH 45/70] chore: consertos gerais --- src/helpers/general_helpers.js | 2 +- src/helpers/trucate.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/helpers/general_helpers.js b/src/helpers/general_helpers.js index 5dd2ca0..4c28c75 100644 --- a/src/helpers/general_helpers.js +++ b/src/helpers/general_helpers.js @@ -1,6 +1,6 @@ /** * - * @param {String} obj - + * @param {Object} obj - */ function formatObject(obj) { return JSON.stringify(obj, null, 2); diff --git a/src/helpers/trucate.js b/src/helpers/trucate.js index 49988e9..12f3cc3 100644 --- a/src/helpers/trucate.js +++ b/src/helpers/trucate.js @@ -1,17 +1,17 @@ -import { pool } from './database.js'; +import { pool } from '../database/database.js'; /** * @param {String} table * */ function truncateTable(table) { - return `TRUNCATE TABLE ${table}`; + return `TRUNCATE TABLE ${table} CASCADE;`; } async function truncateUsersTable() { - const query = truncateTable('users'); + const query = truncateTable('users'); - await pool.query(query); + await pool.query(query); } export { truncateUsersTable }; From 89157a4cd3e7add4ea290c4124060beea2af0cde Mon Sep 17 00:00:00 2001 From: ItzTas Date: Fri, 16 Aug 2024 23:05:56 -0400 Subject: [PATCH 46/70] test: teste erro 404 e 401 --- test/controllers/users_controller.test.js | 128 +++++++++++++++++----- 1 file changed, 98 insertions(+), 30 deletions(-) diff --git a/test/controllers/users_controller.test.js b/test/controllers/users_controller.test.js index e6544ce..d454fb3 100644 --- a/test/controllers/users_controller.test.js +++ b/test/controllers/users_controller.test.js @@ -1,22 +1,25 @@ -import supertest from "supertest"; -import app from "../../src/index.js"; +import supertest from 'supertest'; +import app from '../../src/index.js'; //import { truncateUsersTable } from '../../src/database/trucate.js'; -import { pool } from "../../src/database/database.js"; -import { formatObject } from "../../src/helpers/general_helpers.js"; +import { pool } from '../../src/database/database.js'; +import { formatObject } from '../../src/helpers/general_helpers.js'; +import { truncateUsersTable } from '../../src/helpers/trucate.js'; -// beforeEach(async () => { -// await truncateUsersTable(); -// }); +beforeEach(async () => { + await truncateUsersTable(); +}); + +afterEach(async () => { + await truncateUsersTable(); +}); -// afterEach(async () => { -// await truncateUsersTable(); -// }); +describe('POST /usuario/login login', () => { + const path = '/usuario/login'; -describe("POST /usuario/login login", () => { - it("Status 200: A rota deve verificar os dados e liberar o acesso", async () => { + it('Status 200: A rota deve verificar os dados e liberar o acesso', async () => { const body = { - user_name: "tales", - password: "123", + user_name: 'tales', + password: '123', }; await pool.query( @@ -27,7 +30,7 @@ describe("POST /usuario/login login", () => { [body.user_name, body.password] ); await supertest(app) - .post("/usuario/login") + .post(path) .send(body) .expect((res) => { const { body, status } = res; @@ -43,36 +46,101 @@ describe("POST /usuario/login login", () => { }); }); - it("Status 400: Deve dar erro se o body estiver incompleto", async () => { + it('Status 400: Deve dar erro se o body estiver incompleto', async () => { const testes = [ { - teste_name: "semSenha", - user_name: "tales", + teste_name: 'deve dar erro se não mandar password', + user_name: 'tales', }, { - teste_name: "semNome", - password: "123", + teste_name: 'deve dar erro se não mandar user name', + password: '123', }, ]; + for (const test of testes) { + await supertest(app) + .post(path) + .send(test) + .expect((res) => { + const { body, status } = res; + + try { + expect(status).toBe(400); + expect(body).toHaveProperty( + 'error', + 'password or user name not provided' + ); + } catch (error) { + throw new Error(` + teste_name: \n${test.teste_name}\n + body: \n${formatObject(body)}\n + status: \n${status}\n + error: \n${error}\n + `); + } + }); + } + }); + + it('Status 404: deve dar erro se o usuario não existir', async () => { + const test = { + user_name: 's9fg8w7qeg0fbwe08fgd89wegq8hf832ghdfs', + password: '1203746dsgfi', + }; + await supertest(app) - .post("/usuario/login") - .send(testes) + .post(path) + .send(test) .expect((res) => { const { body, status } = res; try { - expect(status).toBe(400); + expect(status).toBe(404); expect(body).toHaveProperty( - "error", - "password or user name not provided" + 'error', + 'user with given name does not exist' ); - } catch (error) { + } catch (err) { throw new Error(` - body: \n${formatObject(body)}\n - status: \n${status}\n - error: \n${error}\n - `); + test: \n${formatObject(test)} \n + body: \n${formatObject(body)} \n + error: \n${err}\n + `); + } + }); + }); + + it('Status 401: deve dar erro se o a senha enviada não corresponder com a do banco de dados', async () => { + const body = { + user_name: 'tales', + password: '123', + }; + + await pool.query( + ` + INSERT INTO "users" (username, password) + VALUES ($1, $2); + `, + [body.user_name, body.password] + ); + await supertest(app) + .post(path) + .send({ + user_name: body.user_name, + password: body.password + 'super errado essa senha', + }) + .expect((res) => { + const { body, status } = res; + try { + expect(status).toBe(401); + expect(body).toHaveProperty('error', 'unauthorized'); + } catch (err) { + throw new Error(` + body: \n${body}\n + status: \n${status}\n + error: \n${err}\n + `); } }); }); From b07f011a34d4a17a19c8c3961d272bc88df48541 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Fri, 16 Aug 2024 23:10:51 -0400 Subject: [PATCH 47/70] chore: comentario removido --- test/controllers/users_controller.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/controllers/users_controller.test.js b/test/controllers/users_controller.test.js index d454fb3..2f3abe0 100644 --- a/test/controllers/users_controller.test.js +++ b/test/controllers/users_controller.test.js @@ -1,6 +1,5 @@ import supertest from 'supertest'; import app from '../../src/index.js'; -//import { truncateUsersTable } from '../../src/database/trucate.js'; import { pool } from '../../src/database/database.js'; import { formatObject } from '../../src/helpers/general_helpers.js'; import { truncateUsersTable } from '../../src/helpers/trucate.js'; From 5745f4a58ba477f94d442ea790d9f77ef9571906 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sat, 17 Aug 2024 15:04:12 -0300 Subject: [PATCH 48/70] ci: ajustando workflow --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b69a9e8..8efdcc1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,5 +49,7 @@ jobs: run: npm clean-install - name: Executando Testes + env: + DATABASE_URL: postgres://user:password@localhost:5432/mydatabase run: npm run test From 5ef18def724761af4cc4bc16d034689e49843a44 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sat, 17 Aug 2024 15:08:26 -0300 Subject: [PATCH 49/70] ci: ajustando workflow --- .github/workflows/ci.yml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8efdcc1..823fbfd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,15 +25,6 @@ jobs: POSTGRES_PASSWORD: $POSTGRES_PASSWORD POSTGRES_DB: $POSTGRES_DATABASE steps: - - name: Verificando Envs - run: | - echo "$POSTGRES_USER" - echo "$POSTGRES_PASSWORD" - echo "$POSTGRES_HOST" - echo "$POSTGRES_PORT" - echo "$POSTGRES_DATABASE" - echo "$JWT_SECRET" - - name: Forçar remoção do diretório run: sudo rm -rf /home/runner/work/projeto-final-trainee-backend/projeto-final-trainee-backend/docker/postgres @@ -48,8 +39,15 @@ jobs: - name: Instalando Dependencias run: npm clean-install + - name: Aguardando inicialização do banco de dados + run: sleep 15s + + - name: Verificar se o banco de dados está acessível + run: | + pg_isready -h localhost -p ${{ env.POSTGRES_PORT }} -U ${{ env.POSTGRES_USER }} + - name: Executando Testes env: - DATABASE_URL: postgres://user:password@localhost:5432/mydatabase + DATABASE_URL: postgres://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@localhost:${{ env.POSTGRES_PORT }}/${{ env.POSTGRES_DATABASE }} run: npm run test From e314f9f4fcdb259e81e561e3b7b073f2b5607466 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sat, 17 Aug 2024 17:49:20 -0300 Subject: [PATCH 50/70] ci: ajustando workflow --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 823fbfd..173f5fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,6 +42,9 @@ jobs: - name: Aguardando inicialização do banco de dados run: sleep 15s + - name: Verificando pgsql + run: psql -c "SHOW listen_addresses; + - name: Verificar se o banco de dados está acessível run: | pg_isready -h localhost -p ${{ env.POSTGRES_PORT }} -U ${{ env.POSTGRES_USER }} From c2c7351d1996bc9949d40e5c9dc8830d48505596 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sat, 17 Aug 2024 17:50:30 -0300 Subject: [PATCH 51/70] ci: ajustando workflow --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 173f5fe..0034ad0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: run: sleep 15s - name: Verificando pgsql - run: psql -c "SHOW listen_addresses; + run: psql -c "SHOW listen_addresses;" - name: Verificar se o banco de dados está acessível run: | From 32bffe93823d1a95053d2b378d6773f2a4f2cfd8 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sat, 17 Aug 2024 17:54:48 -0300 Subject: [PATCH 52/70] ci: ajustando workflow --- .github/workflows/ci.yml | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0034ad0..9ac206e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,12 +21,10 @@ jobs: ports: - 5432:5432 env: - POSTGRES_USER: $POSTGRES_USER - POSTGRES_PASSWORD: $POSTGRES_PASSWORD - POSTGRES_DB: $POSTGRES_DATABASE + POSTGRES_USER: ${{env.POSTGRES_USER}} + POSTGRES_PASSWORD: ${{env.$POSTGRES_PASSWORD}} + POSTGRES_DB: ${{env.POSTGRES_DATABASE}} steps: - - name: Forçar remoção do diretório - run: sudo rm -rf /home/runner/work/projeto-final-trainee-backend/projeto-final-trainee-backend/docker/postgres - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 @@ -39,18 +37,6 @@ jobs: - name: Instalando Dependencias run: npm clean-install - - name: Aguardando inicialização do banco de dados - run: sleep 15s - - - name: Verificando pgsql - run: psql -c "SHOW listen_addresses;" - - - name: Verificar se o banco de dados está acessível - run: | - pg_isready -h localhost -p ${{ env.POSTGRES_PORT }} -U ${{ env.POSTGRES_USER }} - - name: Executando Testes - env: - DATABASE_URL: postgres://${{ env.POSTGRES_USER }}:${{ env.POSTGRES_PASSWORD }}@localhost:${{ env.POSTGRES_PORT }}/${{ env.POSTGRES_DATABASE }} run: npm run test From f962a3f834fd3c88556e4989877d296acb9c01a0 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sat, 17 Aug 2024 17:56:49 -0300 Subject: [PATCH 53/70] ci: ajustando workflow --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ac206e..ab48ed1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,9 +21,9 @@ jobs: ports: - 5432:5432 env: - POSTGRES_USER: ${{env.POSTGRES_USER}} - POSTGRES_PASSWORD: ${{env.$POSTGRES_PASSWORD}} - POSTGRES_DB: ${{env.POSTGRES_DATABASE}} + POSTGRES_USER: $POSTGRES_USER + POSTGRES_PASSWORD: $POSTGRES_PASSWORD + POSTGRES_DB: $POSTGRES_DATABASE steps: - name: Verificação do Repositorio From 9f3cec82dec5b929aa87a939a03bac1e327046f5 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sat, 17 Aug 2024 17:59:52 -0300 Subject: [PATCH 54/70] ci: ajustando workflow --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab48ed1..1678728 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,9 @@ jobs: POSTGRES_DB: $POSTGRES_DATABASE steps: + - name: Modificar permissões + run: sudo chmod -R 777 /home/runner/work/projeto-final-trainee-backend/projeto-final-trainee-backend/docker + - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 From 3f94bd823fad8946fe90ae82b0e3fa404934bc40 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sat, 17 Aug 2024 19:18:02 -0300 Subject: [PATCH 55/70] ci: ajustando workflow --- .github/workflows/ci.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1678728..d72f0ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,10 +20,13 @@ jobs: - ./docker/postgres/projeto-final-ddl.sql:/docker-entrypoint-initdb.d/initdb-projeto-final-ddl.sql ports: - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 env: - POSTGRES_USER: $POSTGRES_USER POSTGRES_PASSWORD: $POSTGRES_PASSWORD - POSTGRES_DB: $POSTGRES_DATABASE steps: - name: Modificar permissões @@ -42,4 +45,9 @@ jobs: - name: Executando Testes run: npm run test - + env: + POSTGRES_HOST: ${{env.POSTGRES_HOST}} + POSTGRES_PORT: ${{env.POSTGRES_PORT}} + POSTGRES_USER: ${{env.POSTGRES_USER}} + POSTGRES_PASSWORD: ${{env.POSTGRES_PASSWORD}} + POSTGRES_DATABASE: ${{env.POSTGRES_DATABASE}} From 3c3a1e8970e9aa665b8fdf65c8946b28973de196 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sat, 17 Aug 2024 19:19:14 -0300 Subject: [PATCH 56/70] ci: ajustando workflow --- .github/workflows/ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d72f0ea..f152c7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,11 +20,6 @@ jobs: - ./docker/postgres/projeto-final-ddl.sql:/docker-entrypoint-initdb.d/initdb-projeto-final-ddl.sql ports: - 5432:5432 - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 env: POSTGRES_PASSWORD: $POSTGRES_PASSWORD steps: From 1eac2a24adcaf34ecd3f12aed9a0b5cb1d0c8b44 Mon Sep 17 00:00:00 2001 From: ItzTas Date: Sat, 17 Aug 2024 18:51:14 -0400 Subject: [PATCH 57/70] test: pequeno cheque faltante adicionado --- package-lock.json | 17 +++++++++++++++++ package.json | 1 + test/controllers/users_controller.test.js | 1 + 3 files changed, 19 insertions(+) diff --git a/package-lock.json b/package-lock.json index 9c58d67..84b6885 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,6 +37,7 @@ "globals": "^15.9.0", "husky": "^9.1.4", "jest": "^29.7.0", + "prettier": "3.3.3", "semantic-release": "^24.0.0", "supertest": "^7.0.0", "typescript": "^5.5.4" @@ -10939,6 +10940,22 @@ "dev": true, "license": "MIT" }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", diff --git a/package.json b/package.json index d65c8a0..4ccbe87 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "globals": "^15.9.0", "husky": "^9.1.4", "jest": "^29.7.0", + "prettier": "3.3.3", "semantic-release": "^24.0.0", "supertest": "^7.0.0", "typescript": "^5.5.4" diff --git a/test/controllers/users_controller.test.js b/test/controllers/users_controller.test.js index 2f3abe0..c4ced84 100644 --- a/test/controllers/users_controller.test.js +++ b/test/controllers/users_controller.test.js @@ -35,6 +35,7 @@ describe('POST /usuario/login login', () => { const { body, status } = res; try { expect(status).toBe(200); + expect(body).toHaveProperty('token'); } catch (err) { throw new Error(` body: \n${formatObject(body)}\n From df885ba5e18db9179669f3a736ee82c4763a99c1 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sun, 18 Aug 2024 11:40:58 -0300 Subject: [PATCH 58/70] ci: ajustando workflow --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f152c7f..eaba4e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,6 @@ jobs: env: POSTGRES_PASSWORD: $POSTGRES_PASSWORD steps: - - name: Modificar permissões run: sudo chmod -R 777 /home/runner/work/projeto-final-trainee-backend/projeto-final-trainee-backend/docker @@ -46,3 +45,4 @@ jobs: POSTGRES_USER: ${{env.POSTGRES_USER}} POSTGRES_PASSWORD: ${{env.POSTGRES_PASSWORD}} POSTGRES_DATABASE: ${{env.POSTGRES_DATABASE}} + JWT_SECRET: ${{env.JWT_SECRET}} From 74c4aa3f28f567c53601387e0890aa8a432101e3 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sun, 18 Aug 2024 11:43:06 -0300 Subject: [PATCH 59/70] ci: ajustando workflow --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eaba4e8..d2044c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: ports: - 5432:5432 env: - POSTGRES_PASSWORD: $POSTGRES_PASSWORD + POSTGRES_PASSWORD: ${{env.POSTGRES_PASSWORD}} steps: - name: Modificar permissões run: sudo chmod -R 777 /home/runner/work/projeto-final-trainee-backend/projeto-final-trainee-backend/docker @@ -40,7 +40,7 @@ jobs: - name: Executando Testes run: npm run test env: - POSTGRES_HOST: ${{env.POSTGRES_HOST}} + POSTGRES_HOST: database POSTGRES_PORT: ${{env.POSTGRES_PORT}} POSTGRES_USER: ${{env.POSTGRES_USER}} POSTGRES_PASSWORD: ${{env.POSTGRES_PASSWORD}} From 90306ff460a2bb6280a69ea3a064e1a5e003b6f7 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sun, 18 Aug 2024 11:44:26 -0300 Subject: [PATCH 60/70] ci: ajustando workflow --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2044c7..249ac62 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: - name: Executando Testes run: npm run test env: - POSTGRES_HOST: database + POSTGRES_HOST: ${{env.POSTGRES_HOST}} POSTGRES_PORT: ${{env.POSTGRES_PORT}} POSTGRES_USER: ${{env.POSTGRES_USER}} POSTGRES_PASSWORD: ${{env.POSTGRES_PASSWORD}} From 1b8915a4f978d8c5145b73af432a844082373993 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sun, 18 Aug 2024 11:55:39 -0300 Subject: [PATCH 61/70] ci: ajustando workflow --- .github/workflows/ci.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 249ac62..5122875 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,19 +13,16 @@ env: jobs: CI: runs-on: ubuntu-latest - services: - database: - image: postgres:16 - volumes: - - ./docker/postgres/projeto-final-ddl.sql:/docker-entrypoint-initdb.d/initdb-projeto-final-ddl.sql - ports: - - 5432:5432 - env: - POSTGRES_PASSWORD: ${{env.POSTGRES_PASSWORD}} steps: - name: Modificar permissões run: sudo chmod -R 777 /home/runner/work/projeto-final-trainee-backend/projeto-final-trainee-backend/docker + - name: Docker Compose Action + uses: hoverkraft-tech/compose-action@v2.0.1 + with: + services: database + compose-file: ./docker-compose.yml + - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 From dabf634bc4ea9cf974a78e9b583dc34f3b98adb4 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sun, 18 Aug 2024 11:56:59 -0300 Subject: [PATCH 62/70] ci: ajustando workflow --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5122875..a3ab9f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,8 +14,6 @@ jobs: CI: runs-on: ubuntu-latest steps: - - name: Modificar permissões - run: sudo chmod -R 777 /home/runner/work/projeto-final-trainee-backend/projeto-final-trainee-backend/docker - name: Docker Compose Action uses: hoverkraft-tech/compose-action@v2.0.1 @@ -23,6 +21,9 @@ jobs: services: database compose-file: ./docker-compose.yml + - name: Modificar permissões + run: sudo chmod -R 777 /home/runner/work/projeto-final-trainee-backend/projeto-final-trainee-backend/docker + - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 From c6a8a5be94517c2d84c12acfa31fbe5010fb1317 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sun, 18 Aug 2024 11:58:35 -0300 Subject: [PATCH 63/70] ci: ajustando workflow --- .github/workflows/ci.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3ab9f3..2f1218c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,8 @@ jobs: CI: runs-on: ubuntu-latest steps: + - name: Verificação do Repositorio + uses: actions/checkout@v4.1.7 - name: Docker Compose Action uses: hoverkraft-tech/compose-action@v2.0.1 @@ -21,12 +23,6 @@ jobs: services: database compose-file: ./docker-compose.yml - - name: Modificar permissões - run: sudo chmod -R 777 /home/runner/work/projeto-final-trainee-backend/projeto-final-trainee-backend/docker - - - name: Verificação do Repositorio - uses: actions/checkout@v4.1.7 - - name: Configurando Node.Js uses: actions/setup-node@v4.0.3 with: From 9db97b2e5be248aaa9a361b7bdec89468a872dfc Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sun, 18 Aug 2024 13:26:00 -0300 Subject: [PATCH 64/70] ci: ajustando workflow --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f1218c..cfd54ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 - - name: Docker Compose Action + - name: Configurando Docker Compose uses: hoverkraft-tech/compose-action@v2.0.1 with: services: database From 650f1271beed1670062374633815bbf7a68b4682 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sun, 18 Aug 2024 13:51:41 -0300 Subject: [PATCH 65/70] ci: ajustando workflow --- .github/workflows/ci.yml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cfd54ea..ddc51bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,16 +12,27 @@ env: jobs: CI: + services: + database: + image: postgres:16 + ports: + - 5432:5432 + volumes: + - ./docker/postgres/projeto-final-ddl.sql:/docker-entrypoint-initdb.d/init-projeto-final-db.sql + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + runs-on: ubuntu-latest steps: - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 - - name: Configurando Docker Compose - uses: hoverkraft-tech/compose-action@v2.0.1 - with: - services: database - compose-file: ./docker-compose.yml + # - name: Configurando Docker Compose + # uses: hoverkraft-tech/compose-action@v2.0.1 + # with: + # services: database + # compose-file: ./docker-compose.yml - name: Configurando Node.Js uses: actions/setup-node@v4.0.3 From e18c8c0bb7af706314454fe6323c523d9db4e365 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sun, 18 Aug 2024 13:54:02 -0300 Subject: [PATCH 66/70] ci: ajustando workflow --- .github/workflows/ci.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ddc51bd..8ddf174 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,14 +20,17 @@ jobs: volumes: - ./docker/postgres/projeto-final-ddl.sql:/docker-entrypoint-initdb.d/init-projeto-final-db.sql env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres + POSTGRES_USER: 'postgres' + POSTGRES_PASSWORD: 'postgres' runs-on: ubuntu-latest steps: + - name: Permissões + run: sudo chmod -R 777 ./docker + - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 - + # - name: Configurando Docker Compose # uses: hoverkraft-tech/compose-action@v2.0.1 # with: From 505f846650acd3c08ecf2a3c72610d293e704bf8 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:00:20 -0300 Subject: [PATCH 67/70] ci: ajustando workflow --- .github/workflows/ci.yml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ddf174..6ee5d91 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,16 +12,16 @@ env: jobs: CI: - services: - database: - image: postgres:16 - ports: - - 5432:5432 - volumes: - - ./docker/postgres/projeto-final-ddl.sql:/docker-entrypoint-initdb.d/init-projeto-final-db.sql - env: - POSTGRES_USER: 'postgres' - POSTGRES_PASSWORD: 'postgres' + # services: + # database: + # image: postgres:16 + # ports: + # - 5432:5432 + # volumes: + # - ./docker/postgres/projeto-final-ddl.sql:/docker-entrypoint-initdb.d/init-projeto-final-db.sql + # env: + # POSTGRES_USER: 'postgres' + # POSTGRES_PASSWORD: 'postgres' runs-on: ubuntu-latest steps: @@ -31,11 +31,11 @@ jobs: - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 - # - name: Configurando Docker Compose - # uses: hoverkraft-tech/compose-action@v2.0.1 - # with: - # services: database - # compose-file: ./docker-compose.yml + - name: Configurando Docker Compose + uses: hoverkraft-tech/compose-action@v2.0.1 + with: + services: database + compose-file: ./docker-compose.yml - name: Configurando Node.Js uses: actions/setup-node@v4.0.3 From 2d7ed81d23418ab61d810f1957ca4aa7b0f34dc7 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:03:40 -0300 Subject: [PATCH 68/70] ci: ajustando workflow --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ee5d91..1ec1023 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,8 +25,8 @@ jobs: runs-on: ubuntu-latest steps: - - name: Permissões - run: sudo chmod -R 777 ./docker + # - name: Permissões + # run: sudo chmod -R 777 ./docker - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 From 114e28128de9b9b03a64b0c5ae82b13506979e72 Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:33:45 -0300 Subject: [PATCH 69/70] =?UTF-8?q?ci:=20implementa=C3=A7=C3=A3o=20do=20novo?= =?UTF-8?q?=20workflow=20em=20teste=20unitario?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ec1023..e2d6234 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,26 +12,12 @@ env: jobs: CI: - # services: - # database: - # image: postgres:16 - # ports: - # - 5432:5432 - # volumes: - # - ./docker/postgres/projeto-final-ddl.sql:/docker-entrypoint-initdb.d/init-projeto-final-db.sql - # env: - # POSTGRES_USER: 'postgres' - # POSTGRES_PASSWORD: 'postgres' - runs-on: ubuntu-latest steps: - # - name: Permissões - # run: sudo chmod -R 777 ./docker - - name: Verificação do Repositorio uses: actions/checkout@v4.1.7 - - name: Configurando Docker Compose + - name: Iniciando Docker Compose uses: hoverkraft-tech/compose-action@v2.0.1 with: services: database From 090569da40d62f6e657c55a0ddc92166215d3dbf Mon Sep 17 00:00:00 2001 From: Pablo Eduardo <79818595+heyitsmepablo@users.noreply.github.com> Date: Sun, 18 Aug 2024 16:55:54 -0300 Subject: [PATCH 70/70] =?UTF-8?q?chore:=20corre=C3=A7=C3=A3o=20de=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ccbe87..75bbae3 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "dependencies": { "bcrypt": "^5.1.1", "cors": "^2.8.5", - "dotenv": "^16.4.5", "express": "^4.19.2", "helmet": "^7.1.0", "jsonwebtoken": "^9.0.2", @@ -30,6 +29,7 @@ "pg": "^8.12.0" }, "devDependencies": { + "dotenv": "^16.4.5", "@commitlint/config-angular": "^19.3.0", "@commitlint/config-conventional": "^19.2.2", "@eslint/js": "^9.9.0",