From a2d4af45a3be1faf8e3e48358a72aaeac7817e17 Mon Sep 17 00:00:00 2001 From: CookieDasora Date: Tue, 22 Aug 2023 17:47:32 -0300 Subject: [PATCH] Created logout route. Update eslint config file --- .eslintrc.json | 9 +- package-lock.json | 672 ++++++++++++++++++++++- package.json | 1 + src/app.ts | 14 +- src/clients/redis-client.ts | 15 +- src/clients/s3-client.ts | 8 +- src/controllers/comments/create.ts | 10 +- src/controllers/comments/delete.ts | 7 +- src/controllers/comments/fetch-info.ts | 7 +- src/controllers/comments/fetch-likes.ts | 7 +- src/controllers/comments/index.ts | 2 +- src/controllers/comments/update.ts | 10 +- src/controllers/posts/create.ts | 7 +- src/controllers/posts/delete.ts | 7 +- src/controllers/posts/fetch-info.ts | 7 +- src/controllers/posts/fetch-likes.ts | 7 +- src/controllers/posts/index.ts | 2 +- src/controllers/posts/update.ts | 4 +- src/controllers/users-router.ts | 3 +- src/controllers/users/auth.ts | 12 +- src/controllers/users/delete.ts | 4 +- src/controllers/users/fetch-info.ts | 7 +- src/controllers/users/fetch-posts.ts | 7 +- src/controllers/users/follow-user.ts | 4 +- src/controllers/users/index.ts | 4 +- src/controllers/users/like-comment.ts | 4 +- src/controllers/users/like-post.ts | 4 +- src/controllers/users/logout.ts | 14 + src/controllers/users/search-user.ts | 7 +- src/controllers/users/signup.ts | 4 +- src/controllers/users/update-email.ts | 4 +- src/controllers/users/update-name.ts | 4 +- src/controllers/users/update-password.ts | 4 +- src/controllers/users/upload-picture.ts | 11 +- src/helpers/compress-image.ts | 12 +- src/helpers/handle-response.ts | 2 +- src/helpers/http-errors.ts | 4 +- src/helpers/logger.ts | 14 +- src/helpers/notification.ts | 22 +- src/middlewares/authenticated.ts | 22 +- src/middlewares/morgan.ts | 9 +- src/middlewares/rate-limit.ts | 4 +- src/middlewares/upload-image.ts | 14 +- src/services/comments/create.ts | 16 +- src/services/comments/delete.ts | 16 +- src/services/comments/fetch-info.ts | 14 +- src/services/comments/fetch-likes.ts | 12 +- src/services/comments/index.ts | 2 +- src/services/comments/update.ts | 20 +- src/services/posts/create.ts | 8 +- src/services/posts/delete.ts | 8 +- src/services/posts/fetch-info.ts | 14 +- src/services/posts/fetch-likes.ts | 12 +- src/services/posts/index.ts | 2 +- src/services/posts/update.ts | 16 +- src/services/users/auth.ts | 14 +- src/services/users/delete.ts | 8 +- src/services/users/fetch-info.ts | 18 +- src/services/users/fetch-posts.ts | 12 +- src/services/users/follow-user.ts | 24 +- src/services/users/index.ts | 2 +- src/services/users/like-comment.ts | 24 +- src/services/users/like-post.ts | 24 +- src/services/users/search-user.ts | 10 +- src/services/users/signup.ts | 14 +- src/services/users/update-email.ts | 12 +- src/services/users/update-name.ts | 12 +- src/services/users/update-password.ts | 16 +- src/services/users/upload-picture.ts | 12 +- src/socket/index.ts | 14 +- tsconfig.json | 2 +- 71 files changed, 1038 insertions(+), 316 deletions(-) create mode 100644 src/controllers/users/logout.ts diff --git a/.eslintrc.json b/.eslintrc.json index fbd3c36..21629ad 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,16 +3,15 @@ "es2021": true, "node": true }, - "extends": "standard-with-typescript", + "plugins": ["prettier"], + "extends": ["plugin:prettier/recommended"], "parserOptions": { "ecmaVersion": "latest", "sourceType": "module", - "project": [ - "./tsconfig.json" - ] + "project": ["./tsconfig.json"] }, "rules": { "@typescript-eslint/no-misused-promises": "off", "@typescript-eslint/explicit-function-return-type": 1 } -} \ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json index f807beb..fdf397e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,6 +53,7 @@ "eslint-config-standard-with-typescript": "^37.0.0", "eslint-plugin-import": "^2.28.0", "eslint-plugin-n": "^16.0.1", + "eslint-plugin-prettier": "^5.0.0", "eslint-plugin-promise": "^6.1.1", "nodemon": "^3.0.1", "pm2": "^4.2.3", @@ -1451,6 +1452,32 @@ "semver": "bin/semver" } }, + "node_modules/@pkgr/utils": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/@pkgr/utils/-/utils-2.4.2.tgz", + "integrity": "sha512-POgTXhjrTfbTV63DiFXav4lBHiICLKKwDeaKn9Nphwj7WH6m0hMMCaJkMyRWjgtPFyRKRVoMXXjczsTQRDEhYw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.3", + "fast-glob": "^3.3.0", + "is-glob": "^4.0.3", + "open": "^9.1.0", + "picocolors": "^1.0.0", + "tslib": "^2.6.0" + }, + "engines": { + "node": "^12.20.0 || ^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, + "node_modules/@pkgr/utils/node_modules/tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", + "dev": true + }, "node_modules/@pm2/agent": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@pm2/agent/-/agent-1.0.8.tgz", @@ -3507,6 +3534,15 @@ "node": ">= 10.0.0" } }, + "node_modules/big-integer": { + "version": "1.6.51", + "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz", + "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==", + "dev": true, + "engines": { + "node": ">=0.6" + } + }, "node_modules/bin-check": { "version": "4.1.0", "dev": true, @@ -3759,6 +3795,18 @@ "resolved": "https://registry.npmjs.org/bowser/-/bowser-2.11.0.tgz", "integrity": "sha512-AlcaJBi/pqqJBIQ8U9Mcpc9i8Aqxn88Skv5d+xBX006BY5u8N3mGLHa5Lgppa7L/HfwgwLgZ6NYs+Ag6uUmJRA==" }, + "node_modules/bplist-parser": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/bplist-parser/-/bplist-parser-0.2.0.tgz", + "integrity": "sha512-z0M+byMThzQmD9NILRniCUXYsYpjwnlO8N5uCFaCqIOpqRsJCrQL9NK3JsD67CN5a08nF5oIL2bD6loTdHOuKw==", + "dev": true, + "dependencies": { + "big-integer": "^1.6.44" + }, + "engines": { + "node": ">= 5.10.0" + } + }, "node_modules/brace-expansion": { "version": "1.1.11", "license": "MIT", @@ -3810,6 +3858,21 @@ "semver": "^7.0.0" } }, + "node_modules/bundle-name": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/bundle-name/-/bundle-name-3.0.0.tgz", + "integrity": "sha512-PKA4BeSvBpQKQ8iPOGCSiell+N8P+Tf1DlwqmYhpe2gAhKPHn8EYOxVT+ShuGmhg8lN8XiSlS80yiExKXrURlw==", + "dev": true, + "dependencies": { + "run-applescript": "^5.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/busboy": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", @@ -4370,6 +4433,150 @@ "dev": true, "license": "MIT" }, + "node_modules/default-browser": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/default-browser/-/default-browser-4.0.0.tgz", + "integrity": "sha512-wX5pXO1+BrhMkSbROFsyxUm0i/cJEScyNhA4PPxc41ICuv05ZZB/MX28s8aZx6xjmatvebIapF6hLEKEcpneUA==", + "dev": true, + "dependencies": { + "bundle-name": "^3.0.0", + "default-browser-id": "^3.0.0", + "execa": "^7.1.1", + "titleize": "^3.0.0" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/default-browser-id": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/default-browser-id/-/default-browser-id-3.0.0.tgz", + "integrity": "sha512-OZ1y3y0SqSICtE8DE4S8YOE9UZOJ8wO16fKWVP5J1Qz42kV9jcnMVFrEE/noXb/ss3Q4pZIH79kxofzyNNtUNA==", + "dev": true, + "dependencies": { + "bplist-parser": "^0.2.0", + "untildify": "^4.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/default-browser/node_modules/execa": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-7.2.0.tgz", + "integrity": "sha512-UduyVP7TLB5IcAQl+OzLyLcS/l32W/GLg+AhHJ+ow40FOk2U3SAllPwR44v4vmdFwIWqpdwxxpQbF1n5ta9seA==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.3", + "get-stream": "^6.0.1", + "human-signals": "^4.3.0", + "is-stream": "^3.0.0", + "merge-stream": "^2.0.0", + "npm-run-path": "^5.1.0", + "onetime": "^6.0.0", + "signal-exit": "^3.0.7", + "strip-final-newline": "^3.0.0" + }, + "engines": { + "node": "^14.18.0 || ^16.14.0 || >=18.0.0" + }, + "funding": { + "url": "https://github.com/sindresorhus/execa?sponsor=1" + } + }, + "node_modules/default-browser/node_modules/human-signals": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-4.3.1.tgz", + "integrity": "sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ==", + "dev": true, + "engines": { + "node": ">=14.18.0" + } + }, + "node_modules/default-browser/node_modules/is-stream": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", + "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==", + "dev": true, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/default-browser/node_modules/mimic-fn": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", + "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/default-browser/node_modules/npm-run-path": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz", + "integrity": "sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==", + "dev": true, + "dependencies": { + "path-key": "^4.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/default-browser/node_modules/onetime": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz", + "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==", + "dev": true, + "dependencies": { + "mimic-fn": "^4.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/default-browser/node_modules/path-key": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz", + "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/default-browser/node_modules/strip-final-newline": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz", + "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/defer-to-connect": { "version": "2.0.1", "dev": true, @@ -4378,6 +4585,18 @@ "node": ">=10" } }, + "node_modules/define-lazy-prop": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-3.0.0.tgz", + "integrity": "sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/define-properties": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.0.tgz", @@ -5097,6 +5316,35 @@ "eslint": ">=7.0.0" } }, + "node_modules/eslint-plugin-prettier": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.0.0.tgz", + "integrity": "sha512-AgaZCVuYDXHUGxj/ZGu1u8H8CYgDY3iG6w5kUFw4AzMVXzB7VvbKgYR4nATIN+OvUrghMbiDLeimVjVY5ilq3w==", + "dev": true, + "dependencies": { + "prettier-linter-helpers": "^1.0.0", + "synckit": "^0.8.5" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/prettier" + }, + "peerDependencies": { + "@types/eslint": ">=8.0.0", + "eslint": ">=8.0.0", + "prettier": ">=3.0.0" + }, + "peerDependenciesMeta": { + "@types/eslint": { + "optional": true + }, + "eslint-config-prettier": { + "optional": true + } + } + }, "node_modules/eslint-plugin-promise": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-6.1.1.tgz", @@ -5410,15 +5658,22 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "node_modules/fast-diff": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", + "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", + "dev": true + }, "node_modules/fast-fifo": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.0.tgz", "integrity": "sha512-IgfweLvEpwyA4WgiQe9Nx6VV2QkML2NkvZnk1oKnIzXgXdWxuhF7zw4DvLTPZJn6PIUneiAXPF24QmoEqHTjyw==" }, "node_modules/fast-glob": { - "version": "3.2.12", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz", + "integrity": "sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==", "dev": true, - "license": "MIT", "dependencies": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", @@ -6451,6 +6706,21 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-docker": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-3.0.0.tgz", + "integrity": "sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==", + "dev": true, + "bin": { + "is-docker": "cli.js" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-extglob": { "version": "2.1.1", "dev": true, @@ -6491,6 +6761,24 @@ "node": ">=0.10.0" } }, + "node_modules/is-inside-container": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-inside-container/-/is-inside-container-1.0.0.tgz", + "integrity": "sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==", + "dev": true, + "dependencies": { + "is-docker": "^3.0.0" + }, + "bin": { + "is-inside-container": "cli.js" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-negative-zero": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz", @@ -6639,6 +6927,33 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-wsl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", + "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "dev": true, + "dependencies": { + "is-docker": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-wsl/node_modules/is-docker": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", + "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", + "dev": true, + "bin": { + "is-docker": "cli.js" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", @@ -7507,6 +7822,24 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/open": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/open/-/open-9.1.0.tgz", + "integrity": "sha512-OS+QTnw1/4vrf+9hh1jc1jnYjzSG4ttTBB8UxOwAnInG3Uo4ssetzC1ihqaIHjLJnA5GGlRl6QlZXOTQhRBUvg==", + "dev": true, + "dependencies": { + "default-browser": "^4.0.0", + "define-lazy-prop": "^3.0.0", + "is-inside-container": "^1.0.0", + "is-wsl": "^2.2.0" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/optionator": { "version": "0.9.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", @@ -7691,6 +8024,12 @@ "url": "https://github.com/sponsors/Borewit" } }, + "node_modules/picocolors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", + "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", + "dev": true + }, "node_modules/picomatch": { "version": "2.3.1", "dev": true, @@ -7931,6 +8270,18 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, + "node_modules/prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "dependencies": { + "fast-diff": "^1.1.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/prisma": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.0.0.tgz", @@ -8324,6 +8675,21 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/run-applescript": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-5.0.0.tgz", + "integrity": "sha512-XcT5rBksx1QdIhlFOCtgZkB99ZEouFZ1E2Kc2LHqNW13U3/74YGdkQRmThTwxy4QIyookibDKYZOPqX//6BlAg==", + "dev": true, + "dependencies": { + "execa": "^5.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "funding": [ @@ -9091,6 +9457,28 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/synckit": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.5.tgz", + "integrity": "sha512-L1dapNV6vu2s/4Sputv8xGsCdAVlb5nRDMFU/E27D44l5U6cw1g0dGd45uLc+OXjNMmF4ntiMdCimzcjFKQI8Q==", + "dev": true, + "dependencies": { + "@pkgr/utils": "^2.3.1", + "tslib": "^2.5.0" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, + "node_modules/synckit/node_modules/tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", + "dev": true + }, "node_modules/tar": { "version": "6.1.15", "license": "ISC", @@ -9140,6 +9528,18 @@ "dev": true, "license": "MIT" }, + "node_modules/titleize": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/titleize/-/titleize-3.0.0.tgz", + "integrity": "sha512-KxVu8EYHDPBdUYdKZdKtU2aj2XfEx9AfjXxE/Aj0vT06w2icA09Vus1rh6eSu1y01akYg6BjIK/hxyLJINoMLQ==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/to-regex-range": { "version": "5.0.1", "dev": true, @@ -9568,6 +9968,15 @@ "node": ">= 0.8" } }, + "node_modules/untildify": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz", + "integrity": "sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -11156,6 +11565,28 @@ } } }, + "@pkgr/utils": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/@pkgr/utils/-/utils-2.4.2.tgz", + "integrity": "sha512-POgTXhjrTfbTV63DiFXav4lBHiICLKKwDeaKn9Nphwj7WH6m0hMMCaJkMyRWjgtPFyRKRVoMXXjczsTQRDEhYw==", + "dev": true, + "requires": { + "cross-spawn": "^7.0.3", + "fast-glob": "^3.3.0", + "is-glob": "^4.0.3", + "open": "^9.1.0", + "picocolors": "^1.0.0", + "tslib": "^2.6.0" + }, + "dependencies": { + "tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", + "dev": true + } + } + }, "@pm2/agent": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@pm2/agent/-/agent-1.0.8.tgz", @@ -12811,6 +13242,12 @@ "node-addon-api": "^5.0.0" } }, + "big-integer": { + "version": "1.6.51", + "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.51.tgz", + "integrity": "sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==", + "dev": true + }, "bin-check": { "version": "4.1.0", "dev": true, @@ -12980,6 +13417,15 @@ "resolved": "https://registry.npmjs.org/bowser/-/bowser-2.11.0.tgz", "integrity": "sha512-AlcaJBi/pqqJBIQ8U9Mcpc9i8Aqxn88Skv5d+xBX006BY5u8N3mGLHa5Lgppa7L/HfwgwLgZ6NYs+Ag6uUmJRA==" }, + "bplist-parser": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/bplist-parser/-/bplist-parser-0.2.0.tgz", + "integrity": "sha512-z0M+byMThzQmD9NILRniCUXYsYpjwnlO8N5uCFaCqIOpqRsJCrQL9NK3JsD67CN5a08nF5oIL2bD6loTdHOuKw==", + "dev": true, + "requires": { + "big-integer": "^1.6.44" + } + }, "brace-expansion": { "version": "1.1.11", "requires": { @@ -13026,6 +13472,15 @@ "semver": "^7.0.0" } }, + "bundle-name": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/bundle-name/-/bundle-name-3.0.0.tgz", + "integrity": "sha512-PKA4BeSvBpQKQ8iPOGCSiell+N8P+Tf1DlwqmYhpe2gAhKPHn8EYOxVT+ShuGmhg8lN8XiSlS80yiExKXrURlw==", + "dev": true, + "requires": { + "run-applescript": "^5.0.0" + } + }, "busboy": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", @@ -13426,10 +13881,105 @@ "version": "0.1.4", "dev": true }, + "default-browser": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/default-browser/-/default-browser-4.0.0.tgz", + "integrity": "sha512-wX5pXO1+BrhMkSbROFsyxUm0i/cJEScyNhA4PPxc41ICuv05ZZB/MX28s8aZx6xjmatvebIapF6hLEKEcpneUA==", + "dev": true, + "requires": { + "bundle-name": "^3.0.0", + "default-browser-id": "^3.0.0", + "execa": "^7.1.1", + "titleize": "^3.0.0" + }, + "dependencies": { + "execa": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/execa/-/execa-7.2.0.tgz", + "integrity": "sha512-UduyVP7TLB5IcAQl+OzLyLcS/l32W/GLg+AhHJ+ow40FOk2U3SAllPwR44v4vmdFwIWqpdwxxpQbF1n5ta9seA==", + "dev": true, + "requires": { + "cross-spawn": "^7.0.3", + "get-stream": "^6.0.1", + "human-signals": "^4.3.0", + "is-stream": "^3.0.0", + "merge-stream": "^2.0.0", + "npm-run-path": "^5.1.0", + "onetime": "^6.0.0", + "signal-exit": "^3.0.7", + "strip-final-newline": "^3.0.0" + } + }, + "human-signals": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-4.3.1.tgz", + "integrity": "sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ==", + "dev": true + }, + "is-stream": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", + "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==", + "dev": true + }, + "mimic-fn": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", + "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", + "dev": true + }, + "npm-run-path": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.1.0.tgz", + "integrity": "sha512-sJOdmRGrY2sjNTRMbSvluQqg+8X7ZK61yvzBEIDhz4f8z1TZFYABsqjjCBd/0PUNE9M6QDgHJXQkGUEm7Q+l9Q==", + "dev": true, + "requires": { + "path-key": "^4.0.0" + } + }, + "onetime": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-6.0.0.tgz", + "integrity": "sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==", + "dev": true, + "requires": { + "mimic-fn": "^4.0.0" + } + }, + "path-key": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz", + "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==", + "dev": true + }, + "strip-final-newline": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz", + "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==", + "dev": true + } + } + }, + "default-browser-id": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/default-browser-id/-/default-browser-id-3.0.0.tgz", + "integrity": "sha512-OZ1y3y0SqSICtE8DE4S8YOE9UZOJ8wO16fKWVP5J1Qz42kV9jcnMVFrEE/noXb/ss3Q4pZIH79kxofzyNNtUNA==", + "dev": true, + "requires": { + "bplist-parser": "^0.2.0", + "untildify": "^4.0.0" + } + }, "defer-to-connect": { "version": "2.0.1", "dev": true }, + "define-lazy-prop": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-3.0.0.tgz", + "integrity": "sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==", + "dev": true + }, "define-properties": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.0.tgz", @@ -13942,6 +14492,16 @@ "semver": "^7.5.3" } }, + "eslint-plugin-prettier": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.0.0.tgz", + "integrity": "sha512-AgaZCVuYDXHUGxj/ZGu1u8H8CYgDY3iG6w5kUFw4AzMVXzB7VvbKgYR4nATIN+OvUrghMbiDLeimVjVY5ilq3w==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0", + "synckit": "^0.8.5" + } + }, "eslint-plugin-promise": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-6.1.1.tgz", @@ -14150,13 +14710,21 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "fast-diff": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", + "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", + "dev": true + }, "fast-fifo": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.0.tgz", "integrity": "sha512-IgfweLvEpwyA4WgiQe9Nx6VV2QkML2NkvZnk1oKnIzXgXdWxuhF7zw4DvLTPZJn6PIUneiAXPF24QmoEqHTjyw==" }, "fast-glob": { - "version": "3.2.12", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz", + "integrity": "sha512-kNFPyjhh5cKjrUltxs+wFx+ZkbRaxxmZ+X0ZU31SOsxCEtP9VPgtq2teZw1DebupL5GmDaNQ6yKMMVcM41iqDg==", "dev": true, "requires": { "@nodelib/fs.stat": "^2.0.2", @@ -14835,6 +15403,12 @@ "has-tostringtag": "^1.0.0" } }, + "is-docker": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-3.0.0.tgz", + "integrity": "sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==", + "dev": true + }, "is-extglob": { "version": "2.1.1", "dev": true @@ -14857,6 +15431,15 @@ "is-extglob": "^2.1.1" } }, + "is-inside-container": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-inside-container/-/is-inside-container-1.0.0.tgz", + "integrity": "sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==", + "dev": true, + "requires": { + "is-docker": "^3.0.0" + } + }, "is-negative-zero": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz", @@ -14943,6 +15526,23 @@ "call-bind": "^1.0.2" } }, + "is-wsl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", + "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "dev": true, + "requires": { + "is-docker": "^2.0.0" + }, + "dependencies": { + "is-docker": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", + "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", + "dev": true + } + } + }, "isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", @@ -15548,6 +16148,18 @@ "mimic-fn": "^2.1.0" } }, + "open": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/open/-/open-9.1.0.tgz", + "integrity": "sha512-OS+QTnw1/4vrf+9hh1jc1jnYjzSG4ttTBB8UxOwAnInG3Uo4ssetzC1ihqaIHjLJnA5GGlRl6QlZXOTQhRBUvg==", + "dev": true, + "requires": { + "default-browser": "^4.0.0", + "define-lazy-prop": "^3.0.0", + "is-inside-container": "^1.0.0", + "is-wsl": "^2.2.0" + } + }, "optionator": { "version": "0.9.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", @@ -15665,6 +16277,12 @@ "version": "5.0.0", "dev": true }, + "picocolors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", + "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", + "dev": true + }, "picomatch": { "version": "2.3.1", "dev": true @@ -15843,6 +16461,15 @@ "integrity": "sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==", "dev": true }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "prisma": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.0.0.tgz", @@ -16099,6 +16726,15 @@ "glob": "^7.1.3" } }, + "run-applescript": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-5.0.0.tgz", + "integrity": "sha512-XcT5rBksx1QdIhlFOCtgZkB99ZEouFZ1E2Kc2LHqNW13U3/74YGdkQRmThTwxy4QIyookibDKYZOPqX//6BlAg==", + "dev": true, + "requires": { + "execa": "^5.0.0" + } + }, "run-parallel": { "version": "1.2.0", "requires": { @@ -16604,6 +17240,24 @@ "version": "1.0.0", "dev": true }, + "synckit": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.5.tgz", + "integrity": "sha512-L1dapNV6vu2s/4Sputv8xGsCdAVlb5nRDMFU/E27D44l5U6cw1g0dGd45uLc+OXjNMmF4ntiMdCimzcjFKQI8Q==", + "dev": true, + "requires": { + "@pkgr/utils": "^2.3.1", + "tslib": "^2.5.0" + }, + "dependencies": { + "tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", + "dev": true + } + } + }, "tar": { "version": "6.1.15", "requires": { @@ -16649,6 +17303,12 @@ "version": "0.2.0", "dev": true }, + "titleize": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/titleize/-/titleize-3.0.0.tgz", + "integrity": "sha512-KxVu8EYHDPBdUYdKZdKtU2aj2XfEx9AfjXxE/Aj0vT06w2icA09Vus1rh6eSu1y01akYg6BjIK/hxyLJINoMLQ==", + "dev": true + }, "to-regex-range": { "version": "5.0.1", "dev": true, @@ -16923,6 +17583,12 @@ "unpipe": { "version": "1.0.0" }, + "untildify": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz", + "integrity": "sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw==", + "dev": true + }, "uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/package.json b/package.json index c77e82f..83d5df3 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "eslint-config-standard-with-typescript": "^37.0.0", "eslint-plugin-import": "^2.28.0", "eslint-plugin-n": "^16.0.1", + "eslint-plugin-prettier": "^5.0.0", "eslint-plugin-promise": "^6.1.1", "nodemon": "^3.0.1", "pm2": "^4.2.3", diff --git a/src/app.ts b/src/app.ts index 41ef529..f5c88bf 100644 --- a/src/app.ts +++ b/src/app.ts @@ -20,15 +20,17 @@ app.use(morganMiddleware) app.use(limiter) app.use(router) app.use(compression({ level: 9 })) -app.use(cors({ - credentials: true, - origin: '*', // TODO: Add client development (and production too) url - optionsSuccessStatus: 200 -})) +app.use( + cors({ + credentials: true, + origin: '*', // TODO: Add client development (and production too) url + optionsSuccessStatus: 200, + }), +) app.use((_req, res) => { res.status(404).json({ - error: 'Endpoint not found' + error: 'Endpoint not found', }) }) diff --git a/src/clients/redis-client.ts b/src/clients/redis-client.ts index 8e5a0f3..64aa564 100644 --- a/src/clients/redis-client.ts +++ b/src/clients/redis-client.ts @@ -6,16 +6,19 @@ const redisHost = process.env.REDIS_HOST ?? '127.0.0.1' const redisPassword = process.env.REDIS_PASSWORD ?? '' const redisConfig: RedisClientOptions = { - url: `redis://:${redisPassword}@${redisHost}:${redisPort}/0` + url: `redis://:${redisPassword}@${redisHost}:${redisPort}/0`, } const redis = createClient(redisConfig) -redis.connect().then(() => { - logger.info('Successfully connected to Redis') -}).catch((e: Error) => { - logger.error(`Error while connecting to Redis: ${e.message}`) -}) +redis + .connect() + .then(() => { + logger.info('Successfully connected to Redis') + }) + .catch((e: Error) => { + logger.error(`Error while connecting to Redis: ${e.message}`) + }) redis.on('error', async (e: Error) => { logger.error(`Error in Redis client: ${e.message}`) diff --git a/src/clients/s3-client.ts b/src/clients/s3-client.ts index 2478967..b0e955f 100644 --- a/src/clients/s3-client.ts +++ b/src/clients/s3-client.ts @@ -8,16 +8,16 @@ if (process.env.NODE_ENV === 'development') { s3 = new S3Client({ credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? '', - secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? '' + secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? '', }, - endpoint: 'http://127.0.0.1:4566' // Uses localstack instead of aws, make sure to create the bucket first with public-read acl + endpoint: 'http://127.0.0.1:4566', // Uses localstack instead of aws, make sure to create the bucket first with public-read acl }) } else { s3 = new S3Client({ credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? '', - secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? '' - } + secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? '', + }, }) } diff --git a/src/controllers/comments/create.ts b/src/controllers/comments/create.ts index 2bac342..afa03d9 100644 --- a/src/controllers/comments/create.ts +++ b/src/controllers/comments/create.ts @@ -3,19 +3,21 @@ import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' import handleResponse from 'helpers/handle-response' -async function commentCreateController ( +async function commentCreateController( req: Request, - res: Response + res: Response, ): Promise { const { content, postId } = req.body const id = res.locals.user.id if (postId === undefined) { - badRequest(res, 'Expected post id'); return + badRequest(res, 'Expected post id') + return } if (content === undefined) { - badRequest(res, 'Expected comment content'); return + badRequest(res, 'Expected comment content') + return } const result = await comment.create(postId, content, id) diff --git a/src/controllers/comments/delete.ts b/src/controllers/comments/delete.ts index 96f0b7c..c3d6918 100644 --- a/src/controllers/comments/delete.ts +++ b/src/controllers/comments/delete.ts @@ -3,15 +3,16 @@ import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' import handleResponse from 'helpers/handle-response' -async function commentDeleteController ( +async function commentDeleteController( req: Request, - res: Response + res: Response, ): Promise { const { commentId } = req.body const id = res.locals.user.id if (commentId === undefined) { - badRequest(res, 'Expected comment id'); return + badRequest(res, 'Expected comment id') + return } const result = await comment.delete(commentId, id) diff --git a/src/controllers/comments/fetch-info.ts b/src/controllers/comments/fetch-info.ts index 9af150b..1dfc3e3 100644 --- a/src/controllers/comments/fetch-info.ts +++ b/src/controllers/comments/fetch-info.ts @@ -3,14 +3,15 @@ import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' import handleResponse from 'helpers/handle-response' -async function commentFetchController ( +async function commentFetchController( req: Request, - res: Response + res: Response, ): Promise { const commentId = req.query.id as string if (commentId === undefined) { - badRequest(res, 'Expected comment id'); return + badRequest(res, 'Expected comment id') + return } const result = await comment.fetch(commentId) diff --git a/src/controllers/comments/fetch-likes.ts b/src/controllers/comments/fetch-likes.ts index 5926d6d..f3532b0 100644 --- a/src/controllers/comments/fetch-likes.ts +++ b/src/controllers/comments/fetch-likes.ts @@ -3,14 +3,15 @@ import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' import handleResponse from 'helpers/handle-response' -async function commentFetchLikesController ( +async function commentFetchLikesController( req: Request, - res: Response + res: Response, ): Promise { const commentId = req.query.id as string if (commentId === undefined) { - badRequest(res, 'Expected comment id'); return + badRequest(res, 'Expected comment id') + return } const result = await comment.fetchLikes(commentId) diff --git a/src/controllers/comments/index.ts b/src/controllers/comments/index.ts index 2c59176..7007a70 100644 --- a/src/controllers/comments/index.ts +++ b/src/controllers/comments/index.ts @@ -9,7 +9,7 @@ const comments = { delete: commentDeleteController, fetch: commentFetchController, fetchLikes: commentFetchLikesController, - update: commentUpdateController + update: commentUpdateController, } as const export default comments diff --git a/src/controllers/comments/update.ts b/src/controllers/comments/update.ts index ec40898..3a35178 100644 --- a/src/controllers/comments/update.ts +++ b/src/controllers/comments/update.ts @@ -3,19 +3,21 @@ import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' import handleResponse from 'helpers/handle-response' -async function commentUpdateController ( +async function commentUpdateController( req: Request, - res: Response + res: Response, ): Promise { const { commentId, content } = req.body const id = res.locals.user.id if (commentId === undefined) { - badRequest(res, 'Expected comment content'); return + badRequest(res, 'Expected comment content') + return } if (content === undefined) { - badRequest(res, 'Expected content to update'); return + badRequest(res, 'Expected content to update') + return } const result = await comment.update(content, id, commentId) diff --git a/src/controllers/posts/create.ts b/src/controllers/posts/create.ts index f1ba28f..20b15bf 100644 --- a/src/controllers/posts/create.ts +++ b/src/controllers/posts/create.ts @@ -3,15 +3,16 @@ import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' import handleResponse from 'helpers/handle-response' -async function postCreateController ( +async function postCreateController( req: Request, - res: Response + res: Response, ): Promise { const { content } = req.body const id = res.locals.user.id if (content === undefined) { - badRequest(res, 'Expected post content'); return + badRequest(res, 'Expected post content') + return } const result = await post.create(content, id) diff --git a/src/controllers/posts/delete.ts b/src/controllers/posts/delete.ts index 36afc0e..93e286f 100644 --- a/src/controllers/posts/delete.ts +++ b/src/controllers/posts/delete.ts @@ -3,15 +3,16 @@ import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' import handleResponse from 'helpers/handle-response' -async function postDeleteController ( +async function postDeleteController( req: Request, - res: Response + res: Response, ): Promise { const userId = res.locals.user.id const postId = req.body.postId if (postId === undefined) { - badRequest(res, 'Missing post id'); return + badRequest(res, 'Missing post id') + return } const result = await post.delete(postId, userId) diff --git a/src/controllers/posts/fetch-info.ts b/src/controllers/posts/fetch-info.ts index 5709e59..4fdf774 100644 --- a/src/controllers/posts/fetch-info.ts +++ b/src/controllers/posts/fetch-info.ts @@ -3,14 +3,15 @@ import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' import handleResponse from 'helpers/handle-response' -async function postFetchInfoController ( +async function postFetchInfoController( req: Request, - res: Response + res: Response, ): Promise { const id = req.query.id as string if (id === undefined) { - badRequest(res, 'Missing post id'); return + badRequest(res, 'Missing post id') + return } const result = await post.fetch(id) diff --git a/src/controllers/posts/fetch-likes.ts b/src/controllers/posts/fetch-likes.ts index 92c86e4..88e203e 100644 --- a/src/controllers/posts/fetch-likes.ts +++ b/src/controllers/posts/fetch-likes.ts @@ -3,14 +3,15 @@ import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' import handleResponse from 'helpers/handle-response' -async function postFetchLikesController ( +async function postFetchLikesController( req: Request, - res: Response + res: Response, ): Promise { const id = req.query.id as string if (id === undefined) { - badRequest(res, 'Missing post id'); return + badRequest(res, 'Missing post id') + return } const result = await post.fetchLikes(id) diff --git a/src/controllers/posts/index.ts b/src/controllers/posts/index.ts index 1a6e9e1..204d675 100644 --- a/src/controllers/posts/index.ts +++ b/src/controllers/posts/index.ts @@ -9,7 +9,7 @@ const post = { delete: postDeleteController, fetch: postFetchInfoController, fetchLikes: postFetchLikesController, - update: postUpdateController + update: postUpdateController, } as const export default post diff --git a/src/controllers/posts/update.ts b/src/controllers/posts/update.ts index 08cfcdb..eb3220a 100644 --- a/src/controllers/posts/update.ts +++ b/src/controllers/posts/update.ts @@ -2,9 +2,9 @@ import post from 'services/posts' import type { Request, Response } from 'express' import handleResponse from 'helpers/handle-response' -async function postUpdateController ( +async function postUpdateController( req: Request, - res: Response + res: Response, ): Promise { const { postId, content } = req.body const userId = res.locals.user.id diff --git a/src/controllers/users-router.ts b/src/controllers/users-router.ts index 2ce5bf7..ed1d71d 100644 --- a/src/controllers/users-router.ts +++ b/src/controllers/users-router.ts @@ -13,6 +13,7 @@ const usersRouter = Router() usersRouter.get('/fetch-posts', user.fetchPosts) usersRouter.get('/info', user.fetchInfo) usersRouter.get('/search', user.searchUser) +usersRouter.get('/logout', authenticated, user.logout) // POST usersRouter.post('/auth', user.auth) @@ -27,7 +28,7 @@ usersRouter.put( '/profile-picture/upload', authenticated, uploadFile, - user.uploadPicture + user.uploadPicture, ) usersRouter.put('/update-email', authenticated, user.updateEmail) usersRouter.put('/update-name', authenticated, user.updateName) diff --git a/src/controllers/users/auth.ts b/src/controllers/users/auth.ts index 318755d..dbea51d 100644 --- a/src/controllers/users/auth.ts +++ b/src/controllers/users/auth.ts @@ -2,7 +2,7 @@ import user from 'services/users' import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' -async function userAuthController (req: Request, res: Response): Promise { +async function userAuthController(req: Request, res: Response): Promise { const { email, password } = req.body const result = await user.auth({ email, password }) @@ -10,10 +10,12 @@ async function userAuthController (req: Request, res: Response): Promise { if (result instanceof Error) { badRequest(res, result.message) } else { - res.cookie('token', result.token, { - httpOnly: true, - secure: process.env.NODE_ENV === 'production' - }).status(200) + res + .cookie('token', result.token, { + httpOnly: true, + secure: process.env.NODE_ENV === 'production', + }) + .status(200) .json({ message: 'Logged in successfully' }) } } diff --git a/src/controllers/users/delete.ts b/src/controllers/users/delete.ts index 90eda97..9cbb032 100644 --- a/src/controllers/users/delete.ts +++ b/src/controllers/users/delete.ts @@ -2,9 +2,9 @@ import user from 'services/users' import type { Request, Response } from 'express' import handleResponse from 'helpers/handle-response' -async function userDeleteController ( +async function userDeleteController( req: Request, - res: Response + res: Response, ): Promise { const userId = res.locals.user.id const result = await user.delete(userId) diff --git a/src/controllers/users/fetch-info.ts b/src/controllers/users/fetch-info.ts index 120cf8a..3d999d9 100644 --- a/src/controllers/users/fetch-info.ts +++ b/src/controllers/users/fetch-info.ts @@ -3,14 +3,15 @@ import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' import handleResponse from 'helpers/handle-response' -async function userFetchInfoController ( +async function userFetchInfoController( req: Request, - res: Response + res: Response, ): Promise { const username = req.query.u as string if (username === undefined) { - badRequest(res, 'Missing username'); return + badRequest(res, 'Missing username') + return } const result = await user.fetchInfo(username.toLowerCase()) diff --git a/src/controllers/users/fetch-posts.ts b/src/controllers/users/fetch-posts.ts index b12348d..f3eb9ae 100644 --- a/src/controllers/users/fetch-posts.ts +++ b/src/controllers/users/fetch-posts.ts @@ -3,14 +3,15 @@ import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' import handleResponse from 'helpers/handle-response' -async function userFetchPostsController ( +async function userFetchPostsController( req: Request, - res: Response + res: Response, ): Promise { const username = req.query.u as string if (username === undefined) { - badRequest(res, 'Missing username'); return + badRequest(res, 'Missing username') + return } const result = await user.fetchPosts(username) diff --git a/src/controllers/users/follow-user.ts b/src/controllers/users/follow-user.ts index 4386504..42ebb31 100644 --- a/src/controllers/users/follow-user.ts +++ b/src/controllers/users/follow-user.ts @@ -2,9 +2,9 @@ import user from 'services/users' import type { Request, Response } from 'express' import handleResponse from 'helpers/handle-response' -async function userFollowController ( +async function userFollowController( req: Request, - res: Response + res: Response, ): Promise { const userId = res.locals.user.id const { userToFollow } = req.body diff --git a/src/controllers/users/index.ts b/src/controllers/users/index.ts index 7eba408..dea265b 100644 --- a/src/controllers/users/index.ts +++ b/src/controllers/users/index.ts @@ -5,6 +5,7 @@ import userFetchInfoController from './fetch-info' import userFetchPostsController from './fetch-posts' import userLikeCommentController from './like-comment' import userLikePostController from './like-post' +import userLogoutController from './logout' import userSearchController from './search-user' import userSignupController from './signup' import userUpdateEmailController from './update-email' @@ -20,12 +21,13 @@ const user = { follow: userFollowController, likeComment: userLikeCommentController, likePost: userLikePostController, + logout: userLogoutController, searchUser: userSearchController, signup: userSignupController, updateEmail: userUpdateEmailController, updateName: userUpdateNameController, updatePassword: userUpdatePasswordController, - uploadPicture: userUploadPictureController + uploadPicture: userUploadPictureController, } as const export default user diff --git a/src/controllers/users/like-comment.ts b/src/controllers/users/like-comment.ts index 6ae4791..50aa65c 100644 --- a/src/controllers/users/like-comment.ts +++ b/src/controllers/users/like-comment.ts @@ -2,9 +2,9 @@ import user from 'services/users' import type { Request, Response } from 'express' import handleResponse from 'helpers/handle-response' -async function userLikeCommentController ( +async function userLikeCommentController( req: Request, - res: Response + res: Response, ): Promise { const userId = res.locals.user.id const { commentId } = req.body diff --git a/src/controllers/users/like-post.ts b/src/controllers/users/like-post.ts index 9dc6eca..288229b 100644 --- a/src/controllers/users/like-post.ts +++ b/src/controllers/users/like-post.ts @@ -2,9 +2,9 @@ import user from 'services/users' import type { Request, Response } from 'express' import handleResponse from 'helpers/handle-response' -async function userLikePostController ( +async function userLikePostController( req: Request, - res: Response + res: Response, ): Promise { const userId = res.locals.user.id const { postId } = req.body diff --git a/src/controllers/users/logout.ts b/src/controllers/users/logout.ts new file mode 100644 index 0000000..38e9735 --- /dev/null +++ b/src/controllers/users/logout.ts @@ -0,0 +1,14 @@ +import type { Request, Response } from 'express' + +async function userLogoutController( + req: Request, + res: Response, +): Promise { + // @ts-expect-error clearCookie interface does not exists in Response. + return res + .clearCookie('token') + .status(200) + .json({ message: 'Successfully logged out' }) +} + +export default userLogoutController diff --git a/src/controllers/users/search-user.ts b/src/controllers/users/search-user.ts index 9b3f723..aac892c 100644 --- a/src/controllers/users/search-user.ts +++ b/src/controllers/users/search-user.ts @@ -2,14 +2,15 @@ import user from 'services/users' import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' -async function userSearchController ( +async function userSearchController( req: Request, - res: Response + res: Response, ): Promise { const username = req.query.u as string if (username === undefined) { - badRequest(res, 'Missing username'); return + badRequest(res, 'Missing username') + return } const result = await user.searchUser(username) diff --git a/src/controllers/users/signup.ts b/src/controllers/users/signup.ts index 3407b53..2daa090 100644 --- a/src/controllers/users/signup.ts +++ b/src/controllers/users/signup.ts @@ -2,9 +2,9 @@ import user from 'services/users' import type { Request, Response } from 'express' import handleResponse from 'helpers/handle-response' -async function userSignupController ( +async function userSignupController( req: Request, - res: Response + res: Response, ): Promise { const { username, email, password } = req.body diff --git a/src/controllers/users/update-email.ts b/src/controllers/users/update-email.ts index e4fefa5..4fc30d2 100644 --- a/src/controllers/users/update-email.ts +++ b/src/controllers/users/update-email.ts @@ -2,9 +2,9 @@ import user from 'services/users' import type { Request, Response } from 'express' import handleResponse from 'helpers/handle-response' -async function userUpdateEmailController ( +async function userUpdateEmailController( req: Request, - res: Response + res: Response, ): Promise { const { email } = req.body const id = res.locals.user.id diff --git a/src/controllers/users/update-name.ts b/src/controllers/users/update-name.ts index 0dcaf02..160aaa9 100644 --- a/src/controllers/users/update-name.ts +++ b/src/controllers/users/update-name.ts @@ -2,9 +2,9 @@ import user from 'services/users' import type { Request, Response } from 'express' import handleResponse from 'helpers/handle-response' -async function userUpdateNameController ( +async function userUpdateNameController( req: Request, - res: Response + res: Response, ): Promise { const { displayName, username } = req.body const id = res.locals.user.id diff --git a/src/controllers/users/update-password.ts b/src/controllers/users/update-password.ts index c40bef3..9e8ce97 100644 --- a/src/controllers/users/update-password.ts +++ b/src/controllers/users/update-password.ts @@ -2,9 +2,9 @@ import user from 'services/users' import type { Request, Response } from 'express' import handleResponse from 'helpers/handle-response' -async function userUpdatePasswordController ( +async function userUpdatePasswordController( req: Request, - res: Response + res: Response, ): Promise { const { currentPassword, newPassword } = req.body const id = res.locals.user.id diff --git a/src/controllers/users/upload-picture.ts b/src/controllers/users/upload-picture.ts index 6ab44d8..40197fb 100644 --- a/src/controllers/users/upload-picture.ts +++ b/src/controllers/users/upload-picture.ts @@ -4,12 +4,13 @@ import type { Request, Response } from 'express' import { badRequest } from 'helpers/http-errors' import handleResponse from 'helpers/handle-response' -async function userUploadPictureController ( +async function userUploadPictureController( req: Request, - res: Response + res: Response, ): Promise { if (req.file === undefined) { - badRequest(res, 'Expected a JPG or PNG file'); return + badRequest(res, 'Expected a JPG or PNG file') + return } const userId = res.locals.user.id @@ -17,7 +18,9 @@ async function userUploadPictureController ( let url: string if (process.env.NODE_ENV === 'development') { - url = `http://${process.env.AWS_BUCKET ?? ''}.s3.localhost.localstack.cloud:4566/${req.file.key}` + url = `http://${ + process.env.AWS_BUCKET ?? '' + }.s3.localhost.localstack.cloud:4566/${req.file.key}` } else { url = req.file.location } diff --git a/src/helpers/compress-image.ts b/src/helpers/compress-image.ts index c614ec9..1a81551 100644 --- a/src/helpers/compress-image.ts +++ b/src/helpers/compress-image.ts @@ -2,16 +2,16 @@ import sharp from 'sharp' import s3 from 'clients/s3-client' import { GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3' -export default async function compressImage ( +export default async function compressImage( imageName: string, - isProfilePicture: string + isProfilePicture: string, ): Promise> { // Get file from s3 const { Body } = await s3.send( new GetObjectCommand({ Bucket: process.env.AWS_BUCKET ?? '', - Key: imageName - }) + Key: imageName, + }), ) const imageBuffer = await Body?.transformToByteArray() @@ -19,7 +19,7 @@ export default async function compressImage ( const compressedImageBuffer = await sharp(imageBuffer) .resize( isProfilePicture === 'true' ? 200 : undefined, - isProfilePicture === 'true' ? 200 : undefined + isProfilePicture === 'true' ? 200 : undefined, ) .jpeg({ quality: 65 }) .toBuffer() @@ -30,7 +30,7 @@ export default async function compressImage ( Key: imageName, Body: compressedImageBuffer, ContentType: 'image/jpeg', - ContentDisposition: 'inline' + ContentDisposition: 'inline', } const { ETag } = await s3.send(new PutObjectCommand(params)) diff --git a/src/helpers/handle-response.ts b/src/helpers/handle-response.ts index 8afebb9..c62e7ba 100644 --- a/src/helpers/handle-response.ts +++ b/src/helpers/handle-response.ts @@ -1,7 +1,7 @@ import { type Response } from 'express' import { badRequest } from './http-errors' -export default function handleResponse (res: Response, result: any): void { +export default function handleResponse(res: Response, result: any): void { if (result instanceof Error) { badRequest(res, result.message) } else { diff --git a/src/helpers/http-errors.ts b/src/helpers/http-errors.ts index bd79b9d..0b7c54e 100644 --- a/src/helpers/http-errors.ts +++ b/src/helpers/http-errors.ts @@ -3,7 +3,7 @@ import { type Response } from 'express' const sendErrorResponse = ( res: Response, status: number, - message: string + message: string, ): void => { res.status(status).json({ error: message }) } @@ -22,7 +22,7 @@ export const forbidden = (res: Response, message = 'Forbidden'): void => { export const internalServerError = ( res: Response, - message = 'Internal Server Error' + message = 'Internal Server Error', ): void => { sendErrorResponse(res, 500, message) } diff --git a/src/helpers/logger.ts b/src/helpers/logger.ts index 26237fc..a77dcf2 100644 --- a/src/helpers/logger.ts +++ b/src/helpers/logger.ts @@ -5,7 +5,7 @@ const levels = { warn: 1, info: 2, http: 3, - debug: 4 + debug: 4, } const level = (): string => { @@ -20,7 +20,7 @@ const colors = { warn: 'yellow', info: 'green', http: 'magenta', - debug: 'white' + debug: 'white', } winston.addColors(colors) @@ -30,23 +30,23 @@ const format = winston.format.combine( winston.format.colorize({ all: true }), winston.format.printf( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - (info) => `${info.timestamp} ${info.level}: ${info.message}` - ) + info => `${info.timestamp} ${info.level}: ${info.message}`, + ), ) const transports = [ new winston.transports.Console(), new winston.transports.File({ filename: 'logs/error.log', - level: 'error' - }) + level: 'error', + }), ] const logger = winston.createLogger({ level: level(), levels, format, - transports + transports, }) export default logger diff --git a/src/helpers/notification.ts b/src/helpers/notification.ts index e6d6964..ba79658 100644 --- a/src/helpers/notification.ts +++ b/src/helpers/notification.ts @@ -1,11 +1,11 @@ import { type NotificationType } from '@prisma/client' import prisma from 'clients/prisma-client' -export async function createNotification ( +export async function createNotification( fromUserId: string, toUserId: string, content: string, - type: NotificationType + type: NotificationType, ): Promise | Error> { try { await prisma.notifications.create({ @@ -13,7 +13,7 @@ export async function createNotification ( type, fromUserId, toUserId, - content + content, }, include: { fromUser: { @@ -21,10 +21,10 @@ export async function createNotification ( id: true, displayName: true, username: true, - profileImage: true - } - } - } + profileImage: true, + }, + }, + }, }) return {} } catch (_) { @@ -32,12 +32,14 @@ export async function createNotification ( } } -export async function countNotifications (toUserId: string): Promise { +export async function countNotifications( + toUserId: string, +): Promise { try { const count = await prisma.notifications.count({ where: { - toUserId - } + toUserId, + }, }) return count diff --git a/src/middlewares/authenticated.ts b/src/middlewares/authenticated.ts index 73d42d7..c7ec6ce 100644 --- a/src/middlewares/authenticated.ts +++ b/src/middlewares/authenticated.ts @@ -4,32 +4,38 @@ import type { Response, Request, NextFunction } from 'express' import { unauthorized } from 'helpers/http-errors' import type jwtPayload from 'interfaces/jwt' -async function authenticated ( +async function authenticated( req: Request, res: Response, - next: NextFunction + next: NextFunction, ): Promise { try { const token = req.cookies.token if (token === undefined) { - unauthorized(res, 'Missing token'); return + unauthorized(res, 'Missing token') + return } - const { id } = verify(token, process.env.JWT_ACCESS_SECRET ?? '') as jwtPayload + const { id } = verify( + token, + process.env.JWT_ACCESS_SECRET ?? '', + ) as jwtPayload if (id === undefined) { - unauthorized(res, 'Invalid token'); return + unauthorized(res, 'Invalid token') + return } const user = await prisma.user.findFirst({ where: { - id - } + id, + }, }) if (user === undefined) { - unauthorized(res, 'User does not exists'); return + unauthorized(res, 'User does not exists') + return } res.locals.user = user diff --git a/src/middlewares/morgan.ts b/src/middlewares/morgan.ts index deba3f8..bf42475 100644 --- a/src/middlewares/morgan.ts +++ b/src/middlewares/morgan.ts @@ -2,12 +2,11 @@ import morgan, { type StreamOptions } from 'morgan' import logger from 'helpers/logger' const stream: StreamOptions = { - write: (message) => logger.http(message) + write: message => logger.http(message), } -const morganMiddleware = morgan( - ':method :url :status - :response-time ms', - { stream } -) +const morganMiddleware = morgan(':method :url :status - :response-time ms', { + stream, +}) export default morganMiddleware diff --git a/src/middlewares/rate-limit.ts b/src/middlewares/rate-limit.ts index 18eac2d..ba2bab7 100644 --- a/src/middlewares/rate-limit.ts +++ b/src/middlewares/rate-limit.ts @@ -20,8 +20,8 @@ const limiter = rateLimit({ // Store configuration store: new RedisStore({ - sendCommand: async (...args: string[]) => await redis.sendCommand(args) - }) + sendCommand: async (...args: string[]) => await redis.sendCommand(args), + }), }) export default limiter diff --git a/src/middlewares/upload-image.ts b/src/middlewares/upload-image.ts index 01ef952..9431877 100644 --- a/src/middlewares/upload-image.ts +++ b/src/middlewares/upload-image.ts @@ -4,23 +4,23 @@ import multerConfig from 'config/multer' import compressImage from 'helpers/compress-image' import { badRequest } from 'helpers/http-errors' -function uploadImage (req: Request, res: Response, next: NextFunction): void { +function uploadImage(req: Request, res: Response, next: NextFunction): void { const upload = multer(multerConfig).single('image') upload(req, res, async (cb: multer.MulterError | Error | any) => { if (req.res?.locals.user == null) { - badRequest( - res, - 'You must be logged in to upload a profile picture' - ); return + badRequest(res, 'You must be logged in to upload a profile picture') + return } if (cb instanceof multer.MulterError || cb instanceof Error) { - badRequest(res, cb.message); return + badRequest(res, cb.message) + return } if (req.file === undefined) { - badRequest(res, 'Expected file'); return + badRequest(res, 'Expected file') + return } await compressImage(req.file?.key, req.body.isProfilePicture) diff --git a/src/services/comments/create.ts b/src/services/comments/create.ts index 96b2de4..11577b7 100644 --- a/src/services/comments/create.ts +++ b/src/services/comments/create.ts @@ -1,14 +1,14 @@ import prisma from 'clients/prisma-client' -async function commentCreateService ( +async function commentCreateService( postId: string, content: string, - authorId: string + authorId: string, ): Promise | Error> { const post = await prisma.post.findFirst({ where: { - id: postId - } + id: postId, + }, }) if (post === null) { @@ -17,8 +17,8 @@ async function commentCreateService ( const user = await prisma.user.findFirst({ where: { - id: authorId - } + id: authorId, + }, }) if (user === null) { @@ -29,8 +29,8 @@ async function commentCreateService ( data: { content, postId, - userId: authorId - } + userId: authorId, + }, }) return comment diff --git a/src/services/comments/delete.ts b/src/services/comments/delete.ts index 204a16f..4f0965b 100644 --- a/src/services/comments/delete.ts +++ b/src/services/comments/delete.ts @@ -1,13 +1,13 @@ import prisma from 'clients/prisma-client' -async function commentDeleteService ( +async function commentDeleteService( commentId: string, - authorId: string + authorId: string, ): Promise | Error> { const user = await prisma.user.findFirst({ where: { - id: authorId - } + id: authorId, + }, }) if (user === null) { @@ -17,8 +17,8 @@ async function commentDeleteService ( const comment = await prisma.comments.findFirst({ where: { id: commentId, - userId: user.id - } + userId: user.id, + }, }) if (comment === null) { @@ -28,8 +28,8 @@ async function commentDeleteService ( await prisma.comments.deleteMany({ where: { id: comment.id, - userId: user.id - } + userId: user.id, + }, }) return {} diff --git a/src/services/comments/fetch-info.ts b/src/services/comments/fetch-info.ts index d89f9b2..6c52ec1 100644 --- a/src/services/comments/fetch-info.ts +++ b/src/services/comments/fetch-info.ts @@ -1,9 +1,11 @@ import prisma from 'clients/prisma-client' -async function commentFetchService (commentId: string): Promise | Error> { +async function commentFetchService( + commentId: string, +): Promise | Error> { const comment = await prisma.comments.findFirst({ where: { - id: commentId + id: commentId, }, select: { id: true, @@ -15,10 +17,10 @@ async function commentFetchService (commentId: string): Promise { +async function commentFetchLikesService(id: string): Promise { const post = await prisma.commentLike.findMany({ where: { - commentId: id + commentId: id, }, select: { user: { select: { displayName: true, username: true, - profileImage: true - } - } - } + profileImage: true, + }, + }, + }, }) if (post === null) { diff --git a/src/services/comments/index.ts b/src/services/comments/index.ts index 548094f..a4728bb 100644 --- a/src/services/comments/index.ts +++ b/src/services/comments/index.ts @@ -9,7 +9,7 @@ const comment = { delete: commentDeleteService, fetch: commentFetchService, fetchLikes: commentFetchLikesService, - update: commentUpdateService + update: commentUpdateService, } as const export default comment diff --git a/src/services/comments/update.ts b/src/services/comments/update.ts index f5b3b18..7809797 100644 --- a/src/services/comments/update.ts +++ b/src/services/comments/update.ts @@ -1,15 +1,15 @@ import prisma from 'clients/prisma-client' -async function commentUpdateService ( +async function commentUpdateService( content: string, authorId: string, - commentId: string + commentId: string, ): Promise | Error> { const comment = await prisma.comments.findFirst({ where: { id: commentId, - userId: authorId - } + userId: authorId, + }, }) if (comment === null) { @@ -19,10 +19,10 @@ async function commentUpdateService ( const updatedComment = await prisma.comments.update({ where: { id: comment.id, - userId: authorId + userId: authorId, }, data: { - content + content, }, select: { id: true, @@ -33,10 +33,10 @@ async function commentUpdateService ( select: { displayName: true, username: true, - profileImage: true - } - } - } + profileImage: true, + }, + }, + }, }) return updatedComment } diff --git a/src/services/posts/create.ts b/src/services/posts/create.ts index 97431cd..ae1c024 100644 --- a/src/services/posts/create.ts +++ b/src/services/posts/create.ts @@ -1,8 +1,8 @@ import prisma from 'clients/prisma-client' -async function postCreateService ( +async function postCreateService( content: string, - authorId: string + authorId: string, ): Promise | Error> { const user = await prisma.user.findFirst({ where: { id: authorId } }) @@ -13,8 +13,8 @@ async function postCreateService ( const post = await prisma.post.create({ data: { content, - authorId - } + authorId, + }, }) return post diff --git a/src/services/posts/delete.ts b/src/services/posts/delete.ts index 9d79daf..8738701 100644 --- a/src/services/posts/delete.ts +++ b/src/services/posts/delete.ts @@ -1,8 +1,8 @@ import prisma from 'clients/prisma-client' -async function postDeleteService ( +async function postDeleteService( postId: string, - userId: string + userId: string, ): Promise | Error> { const post = await prisma.post.findFirst({ where: { id: postId } }) @@ -20,8 +20,8 @@ async function postDeleteService ( await prisma.post.deleteMany({ where: { - id: postId - } + id: postId, + }, }) return {} diff --git a/src/services/posts/fetch-info.ts b/src/services/posts/fetch-info.ts index db3b576..9aaf9c7 100644 --- a/src/services/posts/fetch-info.ts +++ b/src/services/posts/fetch-info.ts @@ -1,9 +1,11 @@ import prisma from 'clients/prisma-client' -async function postFetchInfoService (id: string): Promise | Error> { +async function postFetchInfoService( + id: string, +): Promise | Error> { const post = await prisma.post.findFirst({ where: { - id + id, }, select: { id: true, @@ -14,10 +16,10 @@ async function postFetchInfoService (id: string): Promise { +async function postFetchLikesService(id: string): Promise { const post = await prisma.postLike.findMany({ where: { - postId: id + postId: id, }, select: { user: { select: { displayName: true, username: true, - profileImage: true - } - } - } + profileImage: true, + }, + }, + }, }) if (post === null) { diff --git a/src/services/posts/index.ts b/src/services/posts/index.ts index ba7f7e3..86f2883 100644 --- a/src/services/posts/index.ts +++ b/src/services/posts/index.ts @@ -9,7 +9,7 @@ const post = { delete: postDeleteService, fetch: postFetchInfoService, fetchLikes: postFetchLikesService, - update: postUpdateService + update: postUpdateService, } as const export default post diff --git a/src/services/posts/update.ts b/src/services/posts/update.ts index ff17cc7..b694e2c 100644 --- a/src/services/posts/update.ts +++ b/src/services/posts/update.ts @@ -1,9 +1,9 @@ import prisma from 'clients/prisma-client' -async function postUpdateService ( +async function postUpdateService( postId: string, content: string, - userId: string + userId: string, ): Promise | Error> { const post = await prisma.post.findFirst({ where: { id: postId } }) @@ -25,10 +25,10 @@ async function postUpdateService ( const updatedPost = await prisma.post.update({ where: { - id: postId + id: postId, }, data: { - content + content, }, select: { id: true, @@ -38,10 +38,10 @@ async function postUpdateService ( author: { select: { displayName: true, - username: true - } - } - } + username: true, + }, + }, + }, }) return updatedPost diff --git a/src/services/users/auth.ts b/src/services/users/auth.ts index 08c1474..d8def6f 100644 --- a/src/services/users/auth.ts +++ b/src/services/users/auth.ts @@ -3,14 +3,14 @@ import jsonwebtoken from 'jsonwebtoken' import prisma from 'clients/prisma-client' import type User from 'interfaces/user' -async function userAuthService ({ +async function userAuthService({ email, - password + password, }: User): Promise | Error> { const user = await prisma.user.findFirst({ where: { - email - } + email, + }, }) if (user == null) { @@ -23,7 +23,7 @@ async function userAuthService ({ const validPassword = await bcrypt.compare( password.replace(/ /g, ''), - user.password + user.password, ) if (!validPassword) { @@ -35,11 +35,11 @@ async function userAuthService ({ const bearer = jsonwebtoken.sign( { id }, process.env.JWT_ACCESS_SECRET ?? '', - { expiresIn: '1d' } + { expiresIn: '1d' }, ) return { - token: bearer + token: bearer, } } diff --git a/src/services/users/delete.ts b/src/services/users/delete.ts index 9af28bf..c872dba 100644 --- a/src/services/users/delete.ts +++ b/src/services/users/delete.ts @@ -1,6 +1,8 @@ import prisma from 'clients/prisma-client' -async function userDeleteService (userId: string): Promise | Error> { +async function userDeleteService( + userId: string, +): Promise | Error> { const user = await prisma.user.findFirst({ where: { id: userId } }) if (user === null) { @@ -13,8 +15,8 @@ async function userDeleteService (userId: string): Promise | Error> { +async function userFetchInfoService( + username: string, +): Promise | Error> { const user = await prisma.user.findFirst({ where: { - username + username, }, select: { profileImage: true, @@ -15,15 +17,15 @@ async function userFetchInfoService (username: string): Promise { const posts = await prisma.post.findMany({ where: { author: { - username - } + username, + }, }, select: { _count: true, id: true, content: true, createdAt: true, - updatedAt: true - } + updatedAt: true, + }, }) return posts } diff --git a/src/services/users/follow-user.ts b/src/services/users/follow-user.ts index 4f0e27d..365ee4c 100644 --- a/src/services/users/follow-user.ts +++ b/src/services/users/follow-user.ts @@ -1,8 +1,8 @@ import prisma from 'clients/prisma-client' -async function userFollowService ( +async function userFollowService( userId: string, - followingUsername: string + followingUsername: string, ): Promise | Error> { if (userId === undefined || followingUsername === undefined) { return new Error('Missing fields') @@ -10,8 +10,8 @@ async function userFollowService ( const user = await prisma.user.findFirst({ where: { - username: followingUsername - } + username: followingUsername, + }, }) if (user === null) { @@ -20,8 +20,8 @@ async function userFollowService ( const userToFollow = await prisma.user.findFirst({ where: { - id: userId - } + id: userId, + }, }) if (userToFollow === null) { @@ -31,16 +31,16 @@ async function userFollowService ( const alreadyFollow = await prisma.follows.findFirst({ where: { followerId: user.id, - followingId: userToFollow.id - } + followingId: userToFollow.id, + }, }) if (alreadyFollow !== null) { await prisma.follows.deleteMany({ where: { followerId: user.id, - followingId: userToFollow.id - } + followingId: userToFollow.id, + }, }) return {} } @@ -48,8 +48,8 @@ async function userFollowService ( const follow = await prisma.follows.create({ data: { followerId: user.id, - followingId: userToFollow.id - } + followingId: userToFollow.id, + }, }) return follow diff --git a/src/services/users/index.ts b/src/services/users/index.ts index 1f30ea9..fad1f8b 100644 --- a/src/services/users/index.ts +++ b/src/services/users/index.ts @@ -25,7 +25,7 @@ const user = { updateEmail: userUpdateEmailService, updateName: userUpdateNameService, updatePassword: userUpdatePasswordService, - uploadPicture: userUploadPictureService + uploadPicture: userUploadPictureService, } as const export default user diff --git a/src/services/users/like-comment.ts b/src/services/users/like-comment.ts index e9134d2..d8617c8 100644 --- a/src/services/users/like-comment.ts +++ b/src/services/users/like-comment.ts @@ -1,8 +1,8 @@ import prisma from 'clients/prisma-client' -async function userLikeCommentService ( +async function userLikeCommentService( commentId: string, - userId: string + userId: string, ): Promise | Error> { if (commentId === undefined || userId === undefined) { return new Error('Missing fields') @@ -10,8 +10,8 @@ async function userLikeCommentService ( const comment = await prisma.comments.findFirst({ where: { - id: commentId - } + id: commentId, + }, }) if (comment === null) { @@ -20,8 +20,8 @@ async function userLikeCommentService ( const user = await prisma.user.findFirst({ where: { - id: userId - } + id: userId, + }, }) if (user === null) { @@ -31,16 +31,16 @@ async function userLikeCommentService ( const alreadyLiked = await prisma.commentLike.findFirst({ where: { commentId: comment.id, - userId: user.id - } + userId: user.id, + }, }) if (alreadyLiked !== null) { await prisma.commentLike.deleteMany({ where: { commentId: comment.id, - userId: user.id - } + userId: user.id, + }, }) return {} } @@ -48,8 +48,8 @@ async function userLikeCommentService ( const like = await prisma.commentLike.create({ data: { commentId: comment.id, - userId: user.id - } + userId: user.id, + }, }) return like diff --git a/src/services/users/like-post.ts b/src/services/users/like-post.ts index b9ce014..ac0d34c 100644 --- a/src/services/users/like-post.ts +++ b/src/services/users/like-post.ts @@ -1,8 +1,8 @@ import prisma from 'clients/prisma-client' -async function userLikePostService ( +async function userLikePostService( postId: string, - userId: string + userId: string, ): Promise | Error> { if (postId === undefined || userId === undefined) { return new Error('Missing fields') @@ -10,8 +10,8 @@ async function userLikePostService ( const post = await prisma.post.findFirst({ where: { - id: postId - } + id: postId, + }, }) if (post === null) { @@ -20,8 +20,8 @@ async function userLikePostService ( const user = await prisma.user.findFirst({ where: { - id: userId - } + id: userId, + }, }) if (user === null) { @@ -31,16 +31,16 @@ async function userLikePostService ( const alreadyLiked = await prisma.postLike.findFirst({ where: { postId: post.id, - userId: user.id - } + userId: user.id, + }, }) if (alreadyLiked !== null) { await prisma.postLike.deleteMany({ where: { postId: post.id, - userId: user.id - } + userId: user.id, + }, }) return {} } @@ -48,8 +48,8 @@ async function userLikePostService ( const like = await prisma.postLike.create({ data: { postId: post.id, - userId: user.id - } + userId: user.id, + }, }) return like diff --git a/src/services/users/search-user.ts b/src/services/users/search-user.ts index f9efe81..2447c22 100644 --- a/src/services/users/search-user.ts +++ b/src/services/users/search-user.ts @@ -1,18 +1,18 @@ import prisma from 'clients/prisma-client' -async function userSearchService (username: string): Promise { +async function userSearchService(username: string): Promise { const users = await prisma.user.findMany({ where: { username: { - contains: username - } + contains: username, + }, }, select: { displayName: true, username: true, - profileImage: true + profileImage: true, }, - take: 10 + take: 10, }) return users } diff --git a/src/services/users/signup.ts b/src/services/users/signup.ts index eb24f09..e9248ba 100644 --- a/src/services/users/signup.ts +++ b/src/services/users/signup.ts @@ -6,10 +6,10 @@ import type User from 'interfaces/user' const passwordRegex = /^(?=.*[0-9])(?=.*[!@#$%^&*_])[a-zA-Z0-9!@#$%^&*_]{8,}$/ const usernameRegex = /^[a-zA-Z0-9_.]{5,15}$/ -async function userSignupService ({ +async function userSignupService({ username, email, - password + password, }: User): Promise | Error> { if (username === undefined || email === undefined || password === undefined) { return new Error('Missing fields') @@ -17,13 +17,13 @@ async function userSignupService ({ if (!passwordRegex.test(password)) { return new Error( - 'Password must have at least 8 characters, one number and one special character.' + 'Password must have at least 8 characters, one number and one special character.', ) } if (!usernameRegex.test(username)) { return new Error( - 'Username not allowed. Only alphanumerics characters (uppercase and lowercase words), underscore, dots and it must be between 5 and 15 characters' + 'Username not allowed. Only alphanumerics characters (uppercase and lowercase words), underscore, dots and it must be between 5 and 15 characters', ) } @@ -46,13 +46,13 @@ async function userSignupService ({ data: { username: username.toLowerCase(), email, - password: hashedPassword + password: hashedPassword, }, select: { displayName: true, username: true, - createdAt: true - } + createdAt: true, + }, }) return user diff --git a/src/services/users/update-email.ts b/src/services/users/update-email.ts index cb803a8..91f48ed 100644 --- a/src/services/users/update-email.ts +++ b/src/services/users/update-email.ts @@ -1,9 +1,9 @@ import type User from 'interfaces/user' import prisma from 'clients/prisma-client' -async function userUpdateEmailService ({ +async function userUpdateEmailService({ id, - email + email, }: User): Promise | Error> { const user = await prisma.user.findFirst({ where: { id } }) @@ -24,16 +24,16 @@ async function userUpdateEmailService ({ await prisma.user.update({ where: { - id + id, }, data: { - email: email ?? user.email + email: email ?? user.email, }, select: { displayName: true, username: true, - createdAt: true - } + createdAt: true, + }, }) return { message: 'Successfully updated user email' } diff --git a/src/services/users/update-name.ts b/src/services/users/update-name.ts index b2a04e9..07df08e 100644 --- a/src/services/users/update-name.ts +++ b/src/services/users/update-name.ts @@ -1,10 +1,10 @@ import type User from 'interfaces/user' import prisma from 'clients/prisma-client' -async function userUpdateNameService ({ +async function userUpdateNameService({ id, displayName, - username + username, }: User): Promise | Error> { const user = await prisma.user.findFirst({ where: { id } }) @@ -28,17 +28,17 @@ async function userUpdateNameService ({ const updatedUser = await prisma.user.update({ where: { - id + id, }, data: { displayName: displayName ?? user.displayName, - username: username ?? user.username + username: username ?? user.username, }, select: { displayName: true, username: true, - createdAt: true - } + createdAt: true, + }, }) return updatedUser diff --git a/src/services/users/update-password.ts b/src/services/users/update-password.ts index bc9a1ef..c9af805 100644 --- a/src/services/users/update-password.ts +++ b/src/services/users/update-password.ts @@ -3,14 +3,14 @@ import prisma from 'clients/prisma-client' const passwordRegex = /^(?=.*[0-9])(?=.*[!@#$%^&*_])[a-zA-Z0-9!@#$%^&*_]{8,}$/ -async function userUpdatePasswordService ( +async function userUpdatePasswordService( id: string, currentPassword: string, - newPassword: string + newPassword: string, ): Promise | Error> { if (!passwordRegex.test(newPassword)) { return new Error( - 'New password must have at least 8 characters, one number and one special character.' + 'New password must have at least 8 characters, one number and one special character.', ) } @@ -26,7 +26,7 @@ async function userUpdatePasswordService ( const validPassword = await bcrypt.compare( currentPassword.replace(/ /g, ''), - user.password + user.password, ) if (!validPassword) { @@ -38,16 +38,16 @@ async function userUpdatePasswordService ( await prisma.user.update({ where: { - id + id, }, data: { - password: hashedPassword + password: hashedPassword, }, select: { displayName: true, username: true, - createdAt: true - } + createdAt: true, + }, }) return { message: 'Successfully updated user password' } diff --git a/src/services/users/upload-picture.ts b/src/services/users/upload-picture.ts index 8131c4d..5756288 100644 --- a/src/services/users/upload-picture.ts +++ b/src/services/users/upload-picture.ts @@ -1,8 +1,8 @@ import prisma from 'clients/prisma-client' -async function userUploadPictureService ( +async function userUploadPictureService( authorId: string, - url: string + url: string, ): Promise | Error> { const user = await prisma.user.findFirst({ where: { id: authorId } }) @@ -12,14 +12,14 @@ async function userUploadPictureService ( const updatedUser = await prisma.user.update({ where: { - id: authorId + id: authorId, }, data: { - profileImage: url + profileImage: url, }, select: { - profileImage: true - } + profileImage: true, + }, }) return updatedUser diff --git a/src/socket/index.ts b/src/socket/index.ts index b2459b2..caddf52 100644 --- a/src/socket/index.ts +++ b/src/socket/index.ts @@ -3,11 +3,11 @@ import logger from 'helpers/logger' import { Server } from 'socket.io' // eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export default function createSocketIOInstance (httpServer: any) { +export default function createSocketIOInstance(httpServer: any) { const io = new Server(httpServer, { cors: { - origin: process.env.CORS_ORIGIN ?? '*' - } + origin: process.env.CORS_ORIGIN ?? '*', + }, }) io.use(async (socket, next) => { @@ -20,11 +20,11 @@ export default function createSocketIOInstance (httpServer: any) { await prisma.user.update({ where: { - id: socket.handshake.auth.id + id: socket.handshake.auth.id, }, data: { - socketId: socket.id - } + socketId: socket.id, + }, }) next() @@ -36,7 +36,7 @@ export default function createSocketIOInstance (httpServer: any) { } */ - io.on('connection', (_) => { + io.on('connection', _ => { logger.info('Placeholder') }) diff --git a/tsconfig.json b/tsconfig.json index c1b9dc1..7673afe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,4 +22,4 @@ "skipLibCheck": true, "resolveJsonModule": true } -} \ No newline at end of file +}