From b93f266f53eb7fe5c468ae828c8c39793f6735f8 Mon Sep 17 00:00:00 2001 From: Ramanjot Singh Date: Sun, 31 Aug 2025 15:59:32 +0530 Subject: [PATCH 01/19] Added user route for uploading bulk users to database added route for bulk adding users --- package-lock.json | 533 ++++++++++++++------------ src/api/controllers/userController.ts | 40 ++ src/api/routes/userRoute.ts | 7 + 3 files changed, 335 insertions(+), 245 deletions(-) diff --git a/package-lock.json b/package-lock.json index b78dfa4..f9d53f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "compression": "^1.7.5", "cookie-parser": "^1.4.7", "cors": "^2.8.5", - "express": "^4.21.2", + "express": "^5.0.1", "html-minifier": "^4.0.0", "jsonwebtoken": "^9.0.2", "mongoose": "^8.8.3", @@ -809,7 +809,7 @@ }, "node_modules/@types/serve-static": { "version": "1.15.7", - "resolved": "https://registry.npmjs.org/@types/serve-@static/-/serve-static-1.15.7.tgz", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.7.tgz", "integrity": "sha512-W8Ym+h8nhuRwaKPaDw34QUkwsGi6Rc4yYqvKFo5rm2FUEhCFbzVWrxXUxuKK8TASjWsysJY0nsmNCGhCOIsrOw==", "dev": true, "license": "MIT", @@ -1060,6 +1060,40 @@ "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", "license": "ISC" }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/accepts/node_modules/mime-types": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.1.tgz", + "integrity": "sha512-xRc4oEhT6eaBpU1XF7AjpOFD+xQmXNB5OVKwp4tqCuBpHLS/ZbBDrc07mYTDqVMg6PfxUjjNp85O6Cd2Z/5HWA==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/accepts/node_modules/negotiator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", + "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/acorn": { "version": "8.14.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz", @@ -1245,12 +1279,6 @@ "dev": true, "license": "Python-2.0" }, - "node_modules/array-flatten": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", - "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", - "license": "MIT" - }, "node_modules/array-union": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", @@ -1503,42 +1531,71 @@ "license": "MIT" }, "node_modules/body-parser": { - "version": "1.20.3", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz", - "integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.2.0.tgz", + "integrity": "sha512-02qvAaxv8tp7fBa/mw1ga98OGm+eCbqzJOKoRt70sLmfEEi+jyBYVTDGfCL/k06/4EMk/z01gCe7HoCH/f2LTg==", "license": "MIT", "dependencies": { - "bytes": "3.1.2", - "content-type": "~1.0.5", - "debug": "2.6.9", - "depd": "2.0.0", - "destroy": "1.2.0", - "http-errors": "2.0.0", - "iconv-lite": "0.4.24", - "on-finished": "2.4.1", - "qs": "6.13.0", - "raw-body": "2.5.2", - "type-is": "~1.6.18", - "unpipe": "1.0.0" + "bytes": "^3.1.2", + "content-type": "^1.0.5", + "debug": "^4.4.0", + "http-errors": "^2.0.0", + "iconv-lite": "^0.6.3", + "on-finished": "^2.4.1", + "qs": "^6.14.0", + "raw-body": "^3.0.0", + "type-is": "^2.0.0" }, "engines": { - "node": ">= 0.10" + "node": ">=18" } }, - "node_modules/body-parser/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "node_modules/body-parser/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", "license": "MIT", "dependencies": { - "ms": "2.0.0" + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" } }, - "node_modules/body-parser/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "license": "MIT" + "node_modules/body-parser/node_modules/media-typer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", + "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/body-parser/node_modules/mime-types": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.1.tgz", + "integrity": "sha512-xRc4oEhT6eaBpU1XF7AjpOFD+xQmXNB5OVKwp4tqCuBpHLS/ZbBDrc07mYTDqVMg6PfxUjjNp85O6Cd2Z/5HWA==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/body-parser/node_modules/type-is": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz", + "integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==", + "license": "MIT", + "dependencies": { + "content-type": "^1.0.5", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 0.6" + } }, "node_modules/brace-expansion": { "version": "2.0.1", @@ -1629,9 +1686,9 @@ } }, "node_modules/call-bind-apply-helpers": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.1.tgz", - "integrity": "sha512-BhYE+WDaywFg2TBWYNXAE+8B1ATnThNBqXHP5nQu0jWJdVvY2hvkpyB3qOmtmDePiS5/BDQ8wASEWGMWRG148g==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", "license": "MIT", "dependencies": { "es-errors": "^1.3.0", @@ -1642,13 +1699,13 @@ } }, "node_modules/call-bound": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.3.tgz", - "integrity": "sha512-YTd+6wGlNlPxSuri7Y6X8tY2dmm12UMH66RpKMhiX6rsk5wXXnYgbUcOt8kiS31/AjfoTOvCsE+w8nZQLQnzHA==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", "license": "MIT", "dependencies": { - "call-bind-apply-helpers": "^1.0.1", - "get-intrinsic": "^1.2.6" + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" }, "engines": { "node": ">= 0.4" @@ -1945,9 +2002,9 @@ "license": "ISC" }, "node_modules/content-disposition": { - "version": "0.5.4", - "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", - "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-1.0.0.tgz", + "integrity": "sha512-Au9nRL8VNUut/XSzbQA38+M78dzP4D+eqg3gfJHMIHHYa3bg067xj1KxMUWj+VULbiZMowKngFFbKczUrNJ1mg==", "license": "MIT", "dependencies": { "safe-buffer": "5.2.1" @@ -2143,16 +2200,6 @@ "node": ">= 0.8" } }, - "node_modules/destroy": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", - "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", - "license": "MIT", - "engines": { - "node": ">= 0.8", - "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", @@ -2607,74 +2654,90 @@ } }, "node_modules/express": { - "version": "4.21.2", - "resolved": "https://registry.npmjs.org/express/-/express-4.21.2.tgz", - "integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==", - "license": "MIT", - "dependencies": { - "accepts": "~1.3.8", - "array-flatten": "1.1.1", - "body-parser": "1.20.3", - "content-disposition": "0.5.4", - "content-type": "~1.0.4", - "cookie": "0.7.1", - "cookie-signature": "1.0.6", - "debug": "2.6.9", - "depd": "2.0.0", - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "finalhandler": "1.3.1", - "fresh": "0.5.2", - "http-errors": "2.0.0", - "merge-descriptors": "1.0.3", - "methods": "~1.1.2", - "on-finished": "2.4.1", - "parseurl": "~1.3.3", - "path-to-regexp": "0.1.12", - "proxy-addr": "~2.0.7", - "qs": "6.13.0", - "range-parser": "~1.2.1", - "safe-buffer": "5.2.1", - "send": "0.19.0", - "serve-static": "1.16.2", - "setprototypeof": "1.2.0", - "statuses": "2.0.1", - "type-is": "~1.6.18", - "utils-merge": "1.0.1", - "vary": "~1.1.2" - }, - "engines": { - "node": ">= 0.10.0" + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/express/-/express-5.1.0.tgz", + "integrity": "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.2.0", + "content-disposition": "^1.0.0", + "content-type": "^1.0.5", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.7", + "qs": "^6.14.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.0.1", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/express" } }, - "node_modules/express/node_modules/cookie": { - "version": "0.7.1", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz", - "integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==", + "node_modules/express/node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", "license": "MIT", "engines": { - "node": ">= 0.6" + "node": ">=6.6.0" } }, - "node_modules/express/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "node_modules/express/node_modules/media-typer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.0.tgz", + "integrity": "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/express/node_modules/mime-types": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.1.tgz", + "integrity": "sha512-xRc4oEhT6eaBpU1XF7AjpOFD+xQmXNB5OVKwp4tqCuBpHLS/ZbBDrc07mYTDqVMg6PfxUjjNp85O6Cd2Z/5HWA==", "license": "MIT", "dependencies": { - "ms": "2.0.0" + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">= 0.6" } }, - "node_modules/express/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "license": "MIT" + "node_modules/express/node_modules/type-is": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.0.1.tgz", + "integrity": "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==", + "license": "MIT", + "dependencies": { + "content-type": "^1.0.5", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 0.6" + } }, "node_modules/extrareqp2": { "version": "1.0.0", @@ -2801,38 +2864,22 @@ } }, "node_modules/finalhandler": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.1.tgz", - "integrity": "sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.0.tgz", + "integrity": "sha512-/t88Ty3d5JWQbWYgaOGCCYfXRwV1+be02WqYYlL6h0lEiUAMPM8o8qKGO01YIkOHzka2up08wvgYD0mDiI+q3Q==", "license": "MIT", "dependencies": { - "debug": "2.6.9", - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "on-finished": "2.4.1", - "parseurl": "~1.3.3", - "statuses": "2.0.1", - "unpipe": "~1.0.0" + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" }, "engines": { "node": ">= 0.8" } }, - "node_modules/finalhandler/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "license": "MIT", - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/finalhandler/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "license": "MIT" - }, "node_modules/find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", @@ -2903,12 +2950,12 @@ } }, "node_modules/fresh": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", - "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", "license": "MIT", "engines": { - "node": ">= 0.6" + "node": ">= 0.8" } }, "node_modules/fs-constants": { @@ -2993,17 +3040,17 @@ } }, "node_modules/get-intrinsic": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.7.tgz", - "integrity": "sha512-VW6Pxhsrk0KAOqs3WEd0klDiF/+V7gQOpAvY1jVU/LHmaD/kQO4523aiJuikX/QAKYiW6x8Jh+RJej1almdtCA==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", "license": "MIT", "dependencies": { - "call-bind-apply-helpers": "^1.0.1", + "call-bind-apply-helpers": "^1.0.2", "es-define-property": "^1.0.1", "es-errors": "^1.3.0", - "es-object-atoms": "^1.0.0", + "es-object-atoms": "^1.1.1", "function-bind": "^1.1.2", - "get-proto": "^1.0.0", + "get-proto": "^1.0.1", "gopd": "^1.2.0", "has-symbols": "^1.1.0", "hasown": "^2.0.2", @@ -3271,6 +3318,15 @@ "node": ">= 0.8" } }, + "node_modules/http-errors/node_modules/statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/http-proxy-agent": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz", @@ -3312,6 +3368,7 @@ "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dev": true, "license": "MIT", "dependencies": { "safer-buffer": ">= 2.1.2 < 3" @@ -3524,6 +3581,12 @@ "node": ">=8" } }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, "node_modules/isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", @@ -3851,10 +3914,13 @@ "license": "MIT" }, "node_modules/merge-descriptors": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", - "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", "license": "MIT", + "engines": { + "node": ">=18" + }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } @@ -3869,15 +3935,6 @@ "node": ">= 8" } }, - "node_modules/methods": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, "node_modules/micromatch": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", @@ -3892,22 +3949,10 @@ "node": ">=8.6" } }, - "node_modules/mime": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", - "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", - "license": "MIT", - "bin": { - "mime": "cli.js" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/mime-db": { - "version": "1.53.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.53.0.tgz", - "integrity": "sha512-oHlN/w+3MQ3rba9rqFr6V/ypF10LSkdwUysQL7GkXoTgIWeV+tcXGA852TBxH+gsh8UWoyhR1hKcoMJTuWflpg==", + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", "license": "MIT", "engines": { "node": ">= 0.6" @@ -4185,9 +4230,10 @@ "license": "MIT" }, "node_modules/multer": { - "version": "1.4.5-lts.1", - "resolved": "https://registry.npmjs.org/multer/-/multer-1.4.5-lts.1.tgz", - "integrity": "sha512-ywPWvcDMeH+z9gQq5qYHCCy+ethsk4goepZ45GLD63fOu0YcNecQxi64nDs3qluZB+murG3/D4dJ7+dGctcCQQ==", + "version": "1.4.5-lts.2", + "resolved": "https://registry.npmjs.org/multer/-/multer-1.4.5-lts.2.tgz", + "integrity": "sha512-VzGiVigcG9zUAoCNU+xShztrlr1auZOlurXynNvO9GiWD1/mTBbUljOKY+qMeazBqXgRnjzeEgJI/wyjJUHg9A==", + "deprecated": "Multer 1.x is impacted by a number of vulnerabilities, which have been patched in 2.x. You should upgrade to the latest 2.x version.", "license": "MIT", "dependencies": { "append-field": "^1.0.0", @@ -4492,9 +4538,9 @@ } }, "node_modules/object-inspect": { - "version": "1.13.3", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.3.tgz", - "integrity": "sha512-kDCGIbxkDSXE3euJZZXzc6to7fCrKHNI/hSRQnRuQ+BWjFNzZwiFF8fj/6o2t2G9/jTj8PSIYTfCLelLZEeRpA==", + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", "license": "MIT", "engines": { "node": ">= 0.4" @@ -4716,10 +4762,13 @@ "license": "MIT" }, "node_modules/path-to-regexp": { - "version": "0.1.12", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz", - "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==", - "license": "MIT" + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", + "integrity": "sha512-TdrF7fW9Rphjq4RjrW0Kp2AW0Ahwu9sRGTkS6bvDi0SCwZlEZYmcfDbEsTz8RVk0EHIS/Vd1bv3JhG+1xZuAyQ==", + "license": "MIT", + "engines": { + "node": ">=16" + } }, "node_modules/path-type": { "version": "4.0.0", @@ -5143,12 +5192,12 @@ } }, "node_modules/qs": { - "version": "6.13.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", - "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz", + "integrity": "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==", "license": "BSD-3-Clause", "dependencies": { - "side-channel": "^1.0.6" + "side-channel": "^1.1.0" }, "engines": { "node": ">=0.6" @@ -5188,14 +5237,14 @@ } }, "node_modules/raw-body": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", - "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.0.tgz", + "integrity": "sha512-RmkhL8CAyCRPXCE28MMH0z2PNWQBNk2Q09ZdxM9IOOXwxwZbN+qbWaatPkdkWIKL2ZVDImrN/pK5HTRz2PcS4g==", "license": "MIT", "dependencies": { "bytes": "3.1.2", "http-errors": "2.0.0", - "iconv-lite": "0.4.24", + "iconv-lite": "0.6.3", "unpipe": "1.0.0" }, "engines": { @@ -5206,6 +5255,7 @@ "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "license": "MIT", "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" }, @@ -5366,6 +5416,22 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -5457,66 +5523,52 @@ } }, "node_modules/send": { - "version": "0.19.0", - "resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz", - "integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.0.tgz", + "integrity": "sha512-uaW0WwXKpL9blXE2o0bRhoL2EGXIrZxQ2ZQ4mgcfoBxdFmQold+qWsD2jLrfZ0trjKL6vOw0j//eAwcALFjKSw==", "license": "MIT", "dependencies": { - "debug": "2.6.9", - "depd": "2.0.0", - "destroy": "1.2.0", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "etag": "~1.8.1", - "fresh": "0.5.2", - "http-errors": "2.0.0", - "mime": "1.6.0", - "ms": "2.1.3", - "on-finished": "2.4.1", - "range-parser": "~1.2.1", - "statuses": "2.0.1" + "debug": "^4.3.5", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "mime-types": "^3.0.1", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.1" }, "engines": { - "node": ">= 0.8.0" + "node": ">= 18" } }, - "node_modules/send/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "node_modules/send/node_modules/mime-types": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.1.tgz", + "integrity": "sha512-xRc4oEhT6eaBpU1XF7AjpOFD+xQmXNB5OVKwp4tqCuBpHLS/ZbBDrc07mYTDqVMg6PfxUjjNp85O6Cd2Z/5HWA==", "license": "MIT", "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/send/node_modules/debug/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "license": "MIT" - }, - "node_modules/send/node_modules/encodeurl": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", - "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", - "license": "MIT", + "mime-db": "^1.54.0" + }, "engines": { - "node": ">= 0.8" + "node": ">= 0.6" } }, "node_modules/serve-static": { - "version": "1.16.2", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.2.tgz", - "integrity": "sha512-VqpjJZKadQB/PEbEwvFdO43Ax5dFBZ2UECszz8bQ7pi7wt//PWe1P6MN7eCnjsatYtBT6EuiClbjSWP2WrIoTw==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.0.tgz", + "integrity": "sha512-61g9pCh0Vnh7IutZjtLGGpTA355+OPn2TyDv/6ivP2h/AdAVX9azsoxmg2/M6nZeQZNYBEwIcsne1mJd9oQItQ==", "license": "MIT", "dependencies": { - "encodeurl": "~2.0.0", - "escape-html": "~1.0.3", - "parseurl": "~1.3.3", - "send": "0.19.0" + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" }, "engines": { - "node": ">= 0.8.0" + "node": ">= 18" } }, "node_modules/set-blocking": { @@ -5839,9 +5891,9 @@ "license": "BSD-3-Clause" }, "node_modules/statuses": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", - "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", "license": "MIT", "engines": { "node": ">= 0.8" @@ -6370,15 +6422,6 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "license": "MIT" }, - "node_modules/utils-merge": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", - "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", - "license": "MIT", - "engines": { - "node": ">= 0.4.0" - } - }, "node_modules/v8-compile-cache-lib": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", diff --git a/src/api/controllers/userController.ts b/src/api/controllers/userController.ts index b9e8953..ba205b1 100644 --- a/src/api/controllers/userController.ts +++ b/src/api/controllers/userController.ts @@ -154,6 +154,46 @@ export const getUserController = asyncErrorHandler(async (req, res, next) => { }); }); +/** + * @description Adds user list to users database. + * @route POST /post-add-users + * @param req - The HTTP request object. + * @param res - The HTTP response object. + * @param next - The next middleware function in the stack. + * @returns A JSON response containing the user database. + * @returns status - Indicates the success status of the operation ('success'). + * @returns message - Describes the outcome of the operation ('User Data successfully inserted'). + * @returns data - Contains the data added to the users database. + * @howItWorks + * - Retrieves the array of users from `req.params.users`. + * - Hashes all the password being added. + * - adds all the data to users models + */ + +export const postBulkUserController = asyncErrorHandler( + async (req, res, next) => { + const usersData = req.body.users; + + if (!Array.isArray(usersData)) { + return res.status(400).json({ error: "user data must be an array" }); + } + + const hashedUsers = await Promise.all( + usersData.map(async (user) => ({ + ...user, + password: await bcrypt.hash(user.password, 10), + })), + ); + + const userDocsInserted = await User.insertMany(hashedUsers); + + res.status(StatusCode.OK).json({ + message: "User Data successfully inserted", + data: userDocsInserted, + }); + }, +); + /** * @description Updates user details including name, email, password, and bio. * @route PUT /update-user diff --git a/src/api/routes/userRoute.ts b/src/api/routes/userRoute.ts index ec56151..3334302 100644 --- a/src/api/routes/userRoute.ts +++ b/src/api/routes/userRoute.ts @@ -7,13 +7,16 @@ import { permsUpdateController, updateUserController, deleteUserController, + postBulkUserController, } from "../controllers/userController"; import { protect } from "../middlewares/authMiddleware"; import protected_route from "../middlewares/permsMiddlewareInit"; import Permission from "@static/types/permissions"; +import { create } from "domain"; const router = express.Router(); +const createBulkProfileProtect = protected_route([Permission.CreateProfile]); const updateProfileProtect = protected_route([Permission.UpdateProfile]); const deleteProfileProtect = protected_route([Permission.DeleteProfile]); @@ -25,6 +28,10 @@ router.route("/current-user").get(protect, getCurrentUserController); router.route("/get-user/:id").get(protect, getUserController); +router + .route("/post-add-users") + .post(protect, createBulkProfileProtect, postBulkUserController); + router .route("/update-user") .put( From 2b9cd573b707a31d023b65747dc4d40e98235b85 Mon Sep 17 00:00:00 2001 From: Ramanjot Singh Date: Sun, 31 Aug 2025 19:23:43 +0530 Subject: [PATCH 02/19] shifted code to authControler and authRouter as well as added random password --- src/api/controllers/authController.ts | 34 +++++++++++++++++++++++++++ src/api/routes/authRouter.ts | 4 ++++ src/api/routes/userRoute.ts | 7 ------ src/api/services/userService.ts | 16 +++++++++++++ 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/api/controllers/authController.ts b/src/api/controllers/authController.ts index 6e63661..a22d9cc 100644 --- a/src/api/controllers/authController.ts +++ b/src/api/controllers/authController.ts @@ -261,6 +261,40 @@ export const login = asyncErrorHandler(async (req, res, next) => { } }); + +/** + * @description Adds user list to users database. + * @route POST /post-add-users + * @param req - The HTTP request object. + * @param res - The HTTP response object. + * @param next - The next middleware function in the stack. + * @returns A JSON response containing the user database. + * @returns status - Indicates the success status of the operation ('success'). + * @returns message - Describes the outcome of the operation ('User Data successfully inserted'). + * @returns data - Contains the data added to the users database. + * @howItWorks + * - Retrieves the array of users from `req.params.users`. + * - Hashes all the password being added. + * - adds all the data to users models + */ + +export const postBulkUserController = asyncErrorHandler( + async (req, res, next) => { + const usersData = req.body.users; + + if (!Array.isArray(usersData)) { + return res.status(400).json({ error: "user data must be an array" }); + } + + const userDocsInserted = await UserService.createNewUsers(usersData); + + res.status(StatusCode.OK).json({ + message: "User Data successfully inserted", + data: userDocsInserted, + }); + }, +); + /** * Handle user password reset request. Send a mail to user with password reset link. */ diff --git a/src/api/routes/authRouter.ts b/src/api/routes/authRouter.ts index 3bed171..3199c70 100644 --- a/src/api/routes/authRouter.ts +++ b/src/api/routes/authRouter.ts @@ -6,6 +6,7 @@ import { forgotPassword, resetPassword, logout, + postBulkUserController } from "../controllers/authController"; import protected_route from "../middlewares/permsMiddlewareInit"; import Permission from "@static/types/permissions"; @@ -17,6 +18,9 @@ const signup_protect = protected_route([Permission.CreateProfile]); router.route("/signup").post(protect, signup_protect, signup); router.post("/login", login); +router + .route("/post-add-users") + .post(protect, signup_protect, postBulkUserController); router.get("/refresh", refresh); router.post("/logout", logout); router.post("/forgotPassword", forgotPassword); diff --git a/src/api/routes/userRoute.ts b/src/api/routes/userRoute.ts index 3334302..ec56151 100644 --- a/src/api/routes/userRoute.ts +++ b/src/api/routes/userRoute.ts @@ -7,16 +7,13 @@ import { permsUpdateController, updateUserController, deleteUserController, - postBulkUserController, } from "../controllers/userController"; import { protect } from "../middlewares/authMiddleware"; import protected_route from "../middlewares/permsMiddlewareInit"; import Permission from "@static/types/permissions"; -import { create } from "domain"; const router = express.Router(); -const createBulkProfileProtect = protected_route([Permission.CreateProfile]); const updateProfileProtect = protected_route([Permission.UpdateProfile]); const deleteProfileProtect = protected_route([Permission.DeleteProfile]); @@ -28,10 +25,6 @@ router.route("/current-user").get(protect, getCurrentUserController); router.route("/get-user/:id").get(protect, getUserController); -router - .route("/post-add-users") - .post(protect, createBulkProfileProtect, postBulkUserController); - router .route("/update-user") .put( diff --git a/src/api/services/userService.ts b/src/api/services/userService.ts index 69fb538..cd7b00c 100644 --- a/src/api/services/userService.ts +++ b/src/api/services/userService.ts @@ -81,3 +81,19 @@ export const createNewUser = async (name: string, email: string) => { return user; }; + +export const createNewUsers = async (users: Array) => { + const hashedUsers = await Promise.all( + users.map(async (user) => { + const password: string = generateRandomPassword(7); + return { + ...user, + password: await bcrypt.hash(password, 10), + } + }), + ); + + const userDocsInserted = await User.insertMany(hashedUsers); + return userDocsInserted; + +} \ No newline at end of file From 93cbbb1db3480d2a9e19b67421b5c0134a611b79 Mon Sep 17 00:00:00 2001 From: Ramanjot Singh Date: Tue, 2 Sep 2025 11:42:40 +0530 Subject: [PATCH 03/19] added functionality for adding role to /signup and /post-add-users --- src/api/controllers/authController.ts | 7 ++--- src/api/controllers/eventController.ts | 20 ++++++------- src/api/controllers/userController.ts | 40 -------------------------- src/api/routes/authRouter.ts | 2 +- src/api/services/userService.ts | 14 +++++---- 5 files changed, 22 insertions(+), 61 deletions(-) diff --git a/src/api/controllers/authController.ts b/src/api/controllers/authController.ts index a22d9cc..8f7145d 100644 --- a/src/api/controllers/authController.ts +++ b/src/api/controllers/authController.ts @@ -142,7 +142,7 @@ export const refresh = asyncErrorHandler(async (req, res, next) => { */ export const signup = asyncErrorHandler(async (req, res, next) => { - const { name, username: email } = req.body; + const { name, username: email, teamRole: role_id } = req.body; if (!email || !name) { const error = new CustomError( @@ -153,7 +153,6 @@ export const signup = asyncErrorHandler(async (req, res, next) => { } const isDuplicate = await UserService.checkUserExists({ email: email }); - console.log(isDuplicate); if (isDuplicate) { const error = new CustomError( @@ -163,7 +162,7 @@ export const signup = asyncErrorHandler(async (req, res, next) => { return next(error); } - await UserService.createNewUser(name, email); + await UserService.createNewUser(name, email, role_id); res.status(StatusCode.CREATED).json({ status: "success", @@ -171,6 +170,7 @@ export const signup = asyncErrorHandler(async (req, res, next) => { data: { name, email, + role_id, }, }); }); @@ -261,7 +261,6 @@ export const login = asyncErrorHandler(async (req, res, next) => { } }); - /** * @description Adds user list to users database. * @route POST /post-add-users diff --git a/src/api/controllers/eventController.ts b/src/api/controllers/eventController.ts index 119183c..29fc3d8 100644 --- a/src/api/controllers/eventController.ts +++ b/src/api/controllers/eventController.ts @@ -3,17 +3,15 @@ import asyncErrorHandler from "../helpers/asyncErrorHandler"; import StatusCode from "@static/types/backend/httpStatusCode"; import { Event, IEvent } from "../models/eventModel"; -export const getEventsController = asyncErrorHandler( - async (req, res, next) => { - const events = await Event.find().sort(); - - res.status(StatusCode.OK).json({ - status: "success", - message: "Events fetched successfully", - data: events, - }); - }, -); +export const getEventsController = asyncErrorHandler(async (req, res, next) => { + const events = await Event.find().sort(); + + res.status(StatusCode.OK).json({ + status: "success", + message: "Events fetched successfully", + data: events, + }); +}); export const createEventController = asyncErrorHandler( async (req, res, next) => { diff --git a/src/api/controllers/userController.ts b/src/api/controllers/userController.ts index ba205b1..b9e8953 100644 --- a/src/api/controllers/userController.ts +++ b/src/api/controllers/userController.ts @@ -154,46 +154,6 @@ export const getUserController = asyncErrorHandler(async (req, res, next) => { }); }); -/** - * @description Adds user list to users database. - * @route POST /post-add-users - * @param req - The HTTP request object. - * @param res - The HTTP response object. - * @param next - The next middleware function in the stack. - * @returns A JSON response containing the user database. - * @returns status - Indicates the success status of the operation ('success'). - * @returns message - Describes the outcome of the operation ('User Data successfully inserted'). - * @returns data - Contains the data added to the users database. - * @howItWorks - * - Retrieves the array of users from `req.params.users`. - * - Hashes all the password being added. - * - adds all the data to users models - */ - -export const postBulkUserController = asyncErrorHandler( - async (req, res, next) => { - const usersData = req.body.users; - - if (!Array.isArray(usersData)) { - return res.status(400).json({ error: "user data must be an array" }); - } - - const hashedUsers = await Promise.all( - usersData.map(async (user) => ({ - ...user, - password: await bcrypt.hash(user.password, 10), - })), - ); - - const userDocsInserted = await User.insertMany(hashedUsers); - - res.status(StatusCode.OK).json({ - message: "User Data successfully inserted", - data: userDocsInserted, - }); - }, -); - /** * @description Updates user details including name, email, password, and bio. * @route PUT /update-user diff --git a/src/api/routes/authRouter.ts b/src/api/routes/authRouter.ts index 3199c70..c8e83da 100644 --- a/src/api/routes/authRouter.ts +++ b/src/api/routes/authRouter.ts @@ -6,7 +6,7 @@ import { forgotPassword, resetPassword, logout, - postBulkUserController + postBulkUserController, } from "../controllers/authController"; import protected_route from "../middlewares/permsMiddlewareInit"; import Permission from "@static/types/permissions"; diff --git a/src/api/services/userService.ts b/src/api/services/userService.ts index cd7b00c..bd27cd1 100644 --- a/src/api/services/userService.ts +++ b/src/api/services/userService.ts @@ -65,7 +65,11 @@ export const getAllUsers = async ( return allUsers; }; -export const createNewUser = async (name: string, email: string) => { +export const createNewUser = async ( + name: string, + email: string, + role_id: string, +) => { const password: string = generateRandomPassword(7); const hashed_password: string = await bcrypt.hash(password, 10); @@ -73,6 +77,7 @@ export const createNewUser = async (name: string, email: string) => { name: name, email: email, password: hashed_password, + role_id: role_id, }); const reg_mail = new RegisterationMail(user, password); @@ -82,18 +87,17 @@ export const createNewUser = async (name: string, email: string) => { return user; }; -export const createNewUsers = async (users: Array) => { +export const createNewUsers = async (users: Array) => { const hashedUsers = await Promise.all( users.map(async (user) => { const password: string = generateRandomPassword(7); return { ...user, password: await bcrypt.hash(password, 10), - } + }; }), ); const userDocsInserted = await User.insertMany(hashedUsers); return userDocsInserted; - -} \ No newline at end of file +}; From 0b5525da8f47b7895acd11fc082f9d435c0f5fac Mon Sep 17 00:00:00 2001 From: Shobhit Tiwari <122107079+Shobhit141141@users.noreply.github.com> Date: Sun, 31 Aug 2025 20:54:12 +0530 Subject: [PATCH 04/19] feat : updated workflow file for new repo and pm2 process name --- .github/workflows/main.yml | 6 +++--- package-lock.json | 10 +++++----- src/commonlib | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 79c5eb9..a87cb93 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,13 +29,13 @@ jobs: run: cd $GITHUB_WORKSPACE - name: Copy source code to target dir - run: rsync -avz $GITHUB_WORKSPACE/ ~/dtutimes-backend/ + run: rsync -avz $GITHUB_WORKSPACE/ ~/TeamPortal/nix-backend/ - name: Get to target dir - run: cd ~/dtutimes-backend + run: cd ~/TeamPortal/nix-backend/ - name: Install dependencies run: npm i - name: Deploy to web - run: pm2 restart NixBackend + run: pm2 restart Backend diff --git a/package-lock.json b/package-lock.json index f9d53f9..4cfd6fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3468,7 +3468,7 @@ "version": "9.0.5", "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz", "integrity": "sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==", - "devOptional": true, + "dev": true, "license": "MIT", "dependencies": { "jsbn": "1.1.0", @@ -3482,7 +3482,7 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz", "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==", - "devOptional": true, + "dev": true, "license": "BSD-3-Clause" }, "node_modules/ipaddr.js": { @@ -3630,7 +3630,7 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==", - "devOptional": true, + "dev": true, "license": "MIT" }, "node_modules/json-buffer": { @@ -5807,7 +5807,7 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==", - "devOptional": true, + "dev": true, "license": "MIT", "engines": { "node": ">= 6.0.0", @@ -5818,7 +5818,7 @@ "version": "2.8.3", "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.3.tgz", "integrity": "sha512-l5x7VUUWbjVFbafGLxPWkYsHIhEvmF85tbIeFZWc8ZPtoMyybuEhL7Jye/ooC4/d48FgOjSJXgsF/AJPYCW8Zw==", - "devOptional": true, + "dev": true, "license": "MIT", "dependencies": { "ip-address": "^9.0.5", diff --git a/src/commonlib b/src/commonlib index d80b881..9dbcd7a 160000 --- a/src/commonlib +++ b/src/commonlib @@ -1 +1 @@ -Subproject commit d80b8819cfd7a596e19072515428f59dd705462c +Subproject commit 9dbcd7a115630cf12bf62cb0e5d261c58d24fbcd From 04f7c3d902c70584f1d09cbdb55f9467682a31b7 Mon Sep 17 00:00:00 2001 From: Shobhit Tiwari <122107079+Shobhit141141@users.noreply.github.com> Date: Sun, 31 Aug 2025 21:04:38 +0530 Subject: [PATCH 05/19] Fix: Update submodule 'commonlib' to the latest commit --- src/commonlib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commonlib b/src/commonlib index 9dbcd7a..d80b881 160000 --- a/src/commonlib +++ b/src/commonlib @@ -1 +1 @@ -Subproject commit 9dbcd7a115630cf12bf62cb0e5d261c58d24fbcd +Subproject commit d80b8819cfd7a596e19072515428f59dd705462c From e5720c23a69912c0078ea367897cfb6b559311eb Mon Sep 17 00:00:00 2001 From: Shobhit Tiwari <122107079+Shobhit141141@users.noreply.github.com> Date: Sun, 31 Aug 2025 21:14:29 +0530 Subject: [PATCH 06/19] feat : update workflows --- .github/workflows/main.yml | 42 +++++++++++++++----------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a87cb93..947ddaf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,41 +1,33 @@ -# This is a basic workflow to help you get started with Actions +# A clear name for your workflow +name: Deploy Backend to Server -name: Deploy on push - -# Controls when the workflow will run +# This workflow runs on any push to the "main" branch on: - # Triggers the workflow on push or pull request events but only for the "main" branch push: branches: [ "main" ] - - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on + deploy: runs-on: home-server - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 + # latest code from your repository + - name: 1. Checkout Repository Code + uses: actions/checkout@v4 with: submodules: true - - name: Get to work dir - run: cd $GITHUB_WORKSPACE - - - name: Copy source code to target dir - run: rsync -avz $GITHUB_WORKSPACE/ ~/TeamPortal/nix-backend/ - - - name: Get to target dir - run: cd ~/TeamPortal/nix-backend/ + # the new code to the live application directory. + - name: 2. Sync Files to Live Directory + run: rsync -avz --delete $GITHUB_WORKSPACE/ /home/dvishal485/TeamPortal/nix-backend/ - - name: Install dependencies - run: npm i + # install dependencies. + - name: 3. Install NPM Dependencies + working-directory: /home/dvishal485/TeamPortal/nix-backend + run: npm install - - name: Deploy to web + # restart the application. + - name: 4. Restart Application with PM2 + working-directory: /home/dvishal485/TeamPortal/nix-backend run: pm2 restart Backend From 8d6a9ece75083af5c65fd1a4ac11d1a3d27590ed Mon Sep 17 00:00:00 2001 From: Shobhit Tiwari <122107079+Shobhit141141@users.noreply.github.com> Date: Sun, 31 Aug 2025 21:21:03 +0530 Subject: [PATCH 07/19] feat: fallback to deployment workflow --- .github/workflows/main.yml | 44 ++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 947ddaf..ca8fddc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,33 +1,41 @@ -# A clear name for your workflow -name: Deploy Backend to Server +# This is a basic workflow to help you get started with Actions -# This workflow runs on any push to the "main" branch +name: Deploy on push + +# Controls when the workflow will run on: + # Triggers the workflow on push or pull request events but only for the "main" branch push: branches: [ "main" ] + + # Allows you to run this workflow manually from the Actions tab workflow_dispatch: +# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - deploy: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on runs-on: home-server + # Steps represent a sequence of tasks that will be executed as part of the job steps: - # latest code from your repository - - name: 1. Checkout Repository Code - uses: actions/checkout@v4 + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 with: submodules: true - # the new code to the live application directory. - - name: 2. Sync Files to Live Directory - run: rsync -avz --delete $GITHUB_WORKSPACE/ /home/dvishal485/TeamPortal/nix-backend/ + - name: Get to work dir + run: cd $GITHUB_WORKSPACE + + - name: Copy source code to target dir + run: rsync -avz $GITHUB_WORKSPACE/ ~/dtutimes-backend/ + + - name: Get to target dir + run: cd ~/dtutimes-backend - # install dependencies. - - name: 3. Install NPM Dependencies - working-directory: /home/dvishal485/TeamPortal/nix-backend - run: npm install + - name: Install dependencies + run: npm i - # restart the application. - - name: 4. Restart Application with PM2 - working-directory: /home/dvishal485/TeamPortal/nix-backend - run: pm2 restart Backend + - name: Deploy to web + run: pm2 restart NixBackend \ No newline at end of file From 6bf04652c9a4d279daeb36b30b19ec54a619bc0a Mon Sep 17 00:00:00 2001 From: Shobhit Tiwari <122107079+Shobhit141141@users.noreply.github.com> Date: Sun, 31 Aug 2025 22:04:14 +0530 Subject: [PATCH 08/19] fix : github workflow --- .github/workflows/main.yml | 42 +++++++++++++++----------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ca8fddc..dbb99a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,41 +1,31 @@ -# This is a basic workflow to help you get started with Actions +name: Deploy Backend to Server -name: Deploy on push - -# Controls when the workflow will run on: - # Triggers the workflow on push or pull request events but only for the "main" branch push: branches: [ "main" ] - - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on + deploy: runs-on: home-server - # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 + # latest code from your repository + - name: 1. Checkout Repository Code + uses: actions/checkout@v4 with: submodules: true - - name: Get to work dir - run: cd $GITHUB_WORKSPACE - - - name: Copy source code to target dir - run: rsync -avz $GITHUB_WORKSPACE/ ~/dtutimes-backend/ - - - name: Get to target dir - run: cd ~/dtutimes-backend + # the new code to the live application directory. + - name: 2. Sync Files to Live Directory + run: rsync -avz --delete $GITHUB_WORKSPACE/ /home/dvishal485/TeamPortal/nix-backend/ - - name: Install dependencies - run: npm i + # install dependencies. + - name: 3. Install NPM Dependencies + working-directory: /home/dvishal485/TeamPortal/nix-backend + run: npm install - - name: Deploy to web - run: pm2 restart NixBackend \ No newline at end of file + # restart the application. + - name: 4. Restart Application with PM2 + working-directory: /home/dvishal485/TeamPortal/nix-backend + run: pm2 restart nix-shell-env From ec6ea40fce1e13be02f436b21c291b076c816048 Mon Sep 17 00:00:00 2001 From: Shobhit Tiwari <122107079+Shobhit141141@users.noreply.github.com> Date: Sun, 31 Aug 2025 22:09:50 +0530 Subject: [PATCH 09/19] fix: remove --delete in deployment workflow --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dbb99a8..465db1f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: # the new code to the live application directory. - name: 2. Sync Files to Live Directory - run: rsync -avz --delete $GITHUB_WORKSPACE/ /home/dvishal485/TeamPortal/nix-backend/ + run: rsync -avz $GITHUB_WORKSPACE/ /home/dvishal485/TeamPortal/nix-backend/ # install dependencies. - name: 3. Install NPM Dependencies From 49a0eec703a6a1994f3b04672a955aaed6d19276 Mon Sep 17 00:00:00 2001 From: Shobhit Tiwari <122107079+Shobhit141141@users.noreply.github.com> Date: Sun, 31 Aug 2025 22:49:03 +0530 Subject: [PATCH 10/19] fix: run PM2 restart command with root --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 465db1f..142488f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,4 +28,4 @@ jobs: # restart the application. - name: 4. Restart Application with PM2 working-directory: /home/dvishal485/TeamPortal/nix-backend - run: pm2 restart nix-shell-env + run: sudo -H -u root pm2 restart nix-shell-env From c4b2a0410f2a93be41d7a9b4925de57f6264b5db Mon Sep 17 00:00:00 2001 From: Shobhit Tiwari <122107079+Shobhit141141@users.noreply.github.com> Date: Sun, 31 Aug 2025 23:45:19 +0530 Subject: [PATCH 11/19] fix: update PM2 restart command to use full path --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 142488f..48e6a4b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,4 +28,5 @@ jobs: # restart the application. - name: 4. Restart Application with PM2 working-directory: /home/dvishal485/TeamPortal/nix-backend - run: sudo -H -u root pm2 restart nix-shell-env + run: /root/.local/share/devbox/global/default/.devbox/nix/profile/default/bin/pm2 restart nix-shell-env + From f0de5ad57e43dc4595752c041d8afd54993a875e Mon Sep 17 00:00:00 2001 From: Shobhit Tiwari <122107079+Shobhit141141@users.noreply.github.com> Date: Mon, 1 Sep 2025 00:12:54 +0530 Subject: [PATCH 12/19] Use sudo to restart application with PM2 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 48e6a4b..9f516aa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,5 +28,5 @@ jobs: # restart the application. - name: 4. Restart Application with PM2 working-directory: /home/dvishal485/TeamPortal/nix-backend - run: /root/.local/share/devbox/global/default/.devbox/nix/profile/default/bin/pm2 restart nix-shell-env + run: sudo /root/.local/share/devbox/global/default/.devbox/nix/profile/default/bin/pm2 restart nix-shell-env From 7c999067f2142e2065677a80e79a64b27a6f5fa4 Mon Sep 17 00:00:00 2001 From: Shobhit Tiwari <122107079+Shobhit141141@users.noreply.github.com> Date: Mon, 1 Sep 2025 00:21:51 +0530 Subject: [PATCH 13/19] Refactor deployment workflow in main.yml Updated deployment workflow to include permission fixes and streamlined commands. --- .github/workflows/main.yml | 52 ++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9f516aa..70ec495 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,32 +1,52 @@ -name: Deploy Backend to Server +name: Deploy +# Controls when the workflow will run on: + # Triggers the workflow on push or pull request events but only for the "main" branch push: branches: [ "main" ] + + # Allows you to run this workflow manually from the Actions tab workflow_dispatch: +# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - deploy: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on runs-on: home-server + # Steps represent a sequence of tasks that will be executed as part of the job steps: - # latest code from your repository - - name: 1. Checkout Repository Code - uses: actions/checkout@v4 + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 with: submodules: true - # the new code to the live application directory. - - name: 2. Sync Files to Live Directory - run: rsync -avz $GITHUB_WORKSPACE/ /home/dvishal485/TeamPortal/nix-backend/ + - name: Get to work dir + run: cd $GITHUB_WORKSPACE - # install dependencies. - - name: 3. Install NPM Dependencies - working-directory: /home/dvishal485/TeamPortal/nix-backend - run: npm install + # Fix permissions for the target directory before rsync + - name: Ensure target directory exists with correct permissions + run: | + mkdir -p /home/dvishal485/TeamPortal/nix-backend + sudo chown -R $USER:$USER /home/dvishal485/TeamPortal/nix-backend + chmod -R 755 /home/dvishal485/TeamPortal/nix-backend - # restart the application. - - name: 4. Restart Application with PM2 - working-directory: /home/dvishal485/TeamPortal/nix-backend - run: sudo /root/.local/share/devbox/global/default/.devbox/nix/profile/default/bin/pm2 restart nix-shell-env + # Copy source code to NEW target dir with permission fixes + - name: Copy source code to target dir + run: rsync -avz --no-group --chmod=D755,F644 $GITHUB_WORKSPACE/ /home/dvishal485/TeamPortal/nix-backend/ + - name: Get to target dir + run: cd /home/dvishal485/TeamPortal/nix-backend + + - name: Install dependencies + run: | + cd /home/dvishal485/TeamPortal/nix-backend + npm i + + # Updated PM2 restart command with correct process name + - name: Deploy to web + run: | + cd /home/dvishal485/TeamPortal/nix-backend + pm2 restart nix-shell-env From 5a68d6c7a1c7c0a1417fbf56435025768344a411 Mon Sep 17 00:00:00 2001 From: Shobhit Tiwari <122107079+Shobhit141141@users.noreply.github.com> Date: Mon, 1 Sep 2025 00:30:12 +0530 Subject: [PATCH 14/19] fix the deployment workflow --- .github/workflows/main.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 70ec495..6e6d84c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,5 @@ -name: Deploy +# This is a basic workflow to help you get started with Actions +name: Deploy on push # Controls when the workflow will run on: @@ -26,16 +27,16 @@ jobs: - name: Get to work dir run: cd $GITHUB_WORKSPACE - # Fix permissions for the target directory before rsync - - name: Ensure target directory exists with correct permissions + # Ensure target directory exists (ownership already fixed) + - name: Ensure target directory exists run: | mkdir -p /home/dvishal485/TeamPortal/nix-backend - sudo chown -R $USER:$USER /home/dvishal485/TeamPortal/nix-backend - chmod -R 755 /home/dvishal485/TeamPortal/nix-backend # Copy source code to NEW target dir with permission fixes - name: Copy source code to target dir - run: rsync -avz --no-group --chmod=D755,F644 $GITHUB_WORKSPACE/ /home/dvishal485/TeamPortal/nix-backend/ + run: | + mkdir -p /home/dvishal485/TeamPortal/nix-backend + rsync -avz --no-group --no-owner --chmod=D755,F644 $GITHUB_WORKSPACE/ /home/dvishal485/TeamPortal/nix-backend/ - name: Get to target dir run: cd /home/dvishal485/TeamPortal/nix-backend From 674887912a1fd2783a920ae8fa1cb3622bc199fe Mon Sep 17 00:00:00 2001 From: Ramanjot Singh Date: Sun, 31 Aug 2025 15:59:32 +0530 Subject: [PATCH 15/19] Added user route for uploading bulk users to database added route for bulk adding users --- src/api/controllers/userController.ts | 40 +++++++++++++++++++++++++++ src/api/routes/userRoute.ts | 7 +++++ 2 files changed, 47 insertions(+) diff --git a/src/api/controllers/userController.ts b/src/api/controllers/userController.ts index b9e8953..ba205b1 100644 --- a/src/api/controllers/userController.ts +++ b/src/api/controllers/userController.ts @@ -154,6 +154,46 @@ export const getUserController = asyncErrorHandler(async (req, res, next) => { }); }); +/** + * @description Adds user list to users database. + * @route POST /post-add-users + * @param req - The HTTP request object. + * @param res - The HTTP response object. + * @param next - The next middleware function in the stack. + * @returns A JSON response containing the user database. + * @returns status - Indicates the success status of the operation ('success'). + * @returns message - Describes the outcome of the operation ('User Data successfully inserted'). + * @returns data - Contains the data added to the users database. + * @howItWorks + * - Retrieves the array of users from `req.params.users`. + * - Hashes all the password being added. + * - adds all the data to users models + */ + +export const postBulkUserController = asyncErrorHandler( + async (req, res, next) => { + const usersData = req.body.users; + + if (!Array.isArray(usersData)) { + return res.status(400).json({ error: "user data must be an array" }); + } + + const hashedUsers = await Promise.all( + usersData.map(async (user) => ({ + ...user, + password: await bcrypt.hash(user.password, 10), + })), + ); + + const userDocsInserted = await User.insertMany(hashedUsers); + + res.status(StatusCode.OK).json({ + message: "User Data successfully inserted", + data: userDocsInserted, + }); + }, +); + /** * @description Updates user details including name, email, password, and bio. * @route PUT /update-user diff --git a/src/api/routes/userRoute.ts b/src/api/routes/userRoute.ts index ec56151..3334302 100644 --- a/src/api/routes/userRoute.ts +++ b/src/api/routes/userRoute.ts @@ -7,13 +7,16 @@ import { permsUpdateController, updateUserController, deleteUserController, + postBulkUserController, } from "../controllers/userController"; import { protect } from "../middlewares/authMiddleware"; import protected_route from "../middlewares/permsMiddlewareInit"; import Permission from "@static/types/permissions"; +import { create } from "domain"; const router = express.Router(); +const createBulkProfileProtect = protected_route([Permission.CreateProfile]); const updateProfileProtect = protected_route([Permission.UpdateProfile]); const deleteProfileProtect = protected_route([Permission.DeleteProfile]); @@ -25,6 +28,10 @@ router.route("/current-user").get(protect, getCurrentUserController); router.route("/get-user/:id").get(protect, getUserController); +router + .route("/post-add-users") + .post(protect, createBulkProfileProtect, postBulkUserController); + router .route("/update-user") .put( From e92a57a586b3f2f1fd8ac02415f66009b7955ba3 Mon Sep 17 00:00:00 2001 From: Shobhit Tiwari <122107079+Shobhit141141@users.noreply.github.com> Date: Fri, 5 Sep 2025 11:50:43 +0530 Subject: [PATCH 16/19] refactor: roll out registration mails for bulk user addition --- src/api/routes/authRouter.ts | 2 +- src/api/services/userService.ts | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/api/routes/authRouter.ts b/src/api/routes/authRouter.ts index c8e83da..1d13055 100644 --- a/src/api/routes/authRouter.ts +++ b/src/api/routes/authRouter.ts @@ -19,7 +19,7 @@ const signup_protect = protected_route([Permission.CreateProfile]); router.route("/signup").post(protect, signup_protect, signup); router.post("/login", login); router - .route("/post-add-users") + .route("/add-members") .post(protect, signup_protect, postBulkUserController); router.get("/refresh", refresh); router.post("/logout", logout); diff --git a/src/api/services/userService.ts b/src/api/services/userService.ts index bd27cd1..478aadb 100644 --- a/src/api/services/userService.ts +++ b/src/api/services/userService.ts @@ -88,16 +88,18 @@ export const createNewUser = async ( }; export const createNewUsers = async (users: Array) => { - const hashedUsers = await Promise.all( - users.map(async (user) => { - const password: string = generateRandomPassword(7); - return { - ...user, - password: await bcrypt.hash(password, 10), - }; - }), - ); - - const userDocsInserted = await User.insertMany(hashedUsers); - return userDocsInserted; + + const createdUsers: HydratedDocument[] = []; + for (const user of users) { + const password: string = generateRandomPassword(7); + const hashed_password: string = await bcrypt.hash(password, 10); + const newUser = await User.create({ + ...user, + password: hashed_password, + }); + const reg_mail = new RegisterationMail(newUser, password); + await reg_mail.sendTo(newUser.email); + createdUsers.push(newUser); + } + return createdUsers; }; From 2bb36499edc2a983883d14a90683f1894848458c Mon Sep 17 00:00:00 2001 From: Ramanjot Singh Date: Fri, 5 Sep 2025 15:48:47 +0530 Subject: [PATCH 17/19] chore ran npm run lint --- .github/workflows/main.yml | 2 +- README.md | 17 ++++++------ tsconfig.json | 54 +++++++++++++++----------------------- 3 files changed, 31 insertions(+), 42 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 79c5eb9..156b51d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,7 +6,7 @@ name: Deploy on push on: # Triggers the workflow on push or pull request events but only for the "main" branch push: - branches: [ "main" ] + branches: ["main"] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: diff --git a/README.md b/README.md index 14bf73a..7f436af 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,15 @@ Refer to .env.local file and create your own .env file as required # Backup Overview 1. **Backup Existence**: The project has a robust backup system in place to ensure data integrity and availability. -2. **MongoDB Backup**: - - **Scope**: All user accounts, passwords, blogs, and other data (excluding images) are backed up. - - **Frequency**: Backups are performed daily. - - **Storage**: The backups are stored on the server and uploaded to the Telegram channel. +2. **MongoDB Backup**: + - **Scope**: All user accounts, passwords, blogs, and other data (excluding images) are backed up. + - **Frequency**: Backups are performed daily. + - **Storage**: The backups are stored on the server and uploaded to the Telegram channel. 3. **Image Backup**: - - **Scope**: All image data is backed up. - - **Frequency**: Backups are performed twice a month (every 15 days). - - **Storage**: Image backups are stored on the server. - - **Notifications**: Notifications are delivered on the same Telegram channel whenever an image backup is completed. + - **Scope**: All image data is backed up. + - **Frequency**: Backups are performed twice a month (every 15 days). + - **Storage**: Image backups are stored on the server. + - **Notifications**: Notifications are delivered on the same Telegram channel whenever an image backup is completed. ## Accessing Server Backups @@ -19,6 +19,7 @@ To access server backups, log in using the following credentials: - **Username**: dvishal485 - Managed via cron jobs + ```bash crontab -e ``` diff --git a/tsconfig.json b/tsconfig.json index 6747728..9672589 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,35 +1,23 @@ { - "compilerOptions": { - "module": "NodeNext", - "moduleResolution": "nodenext", - "target": "ESNext", - "sourceMap": false, - "outDir": "dist", - "allowJs": false, - "strictNullChecks": true, - "typeRoots": [ - "./src/types", - "./node_modules/@types" - ], - "baseUrl": ".", - "paths": { // Adjust based on your project structure - "@/*": [ - "./src/*" - ], - "@static/*": [ - "./src/commonlib/*" - ] - }, - "resolveJsonModule": true + "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "nodenext", + "target": "ESNext", + "sourceMap": false, + "outDir": "dist", + "allowJs": false, + "strictNullChecks": true, + "typeRoots": ["./src/types", "./node_modules/@types"], + "baseUrl": ".", + "paths": { + // Adjust based on your project structure + "@/*": ["./src/*"], + "@static/*": ["./src/commonlib/*"] }, - "ts-node": { - "require": [ - "tsconfig-paths/register" - ] - }, - "exclude": [ - "node_modules", - "dist", - "src/scripts" - ], -} \ No newline at end of file + "resolveJsonModule": true + }, + "ts-node": { + "require": ["tsconfig-paths/register"] + }, + "exclude": ["node_modules", "dist", "src/scripts"] +} From 58fd951b5f7e72dcb56e772291b377a90fe8869a Mon Sep 17 00:00:00 2001 From: Ramanjot Singh Date: Fri, 5 Sep 2025 18:10:01 +0530 Subject: [PATCH 18/19] Added functionality of checking email if already exists or not in auth/add-members route --- .github/workflows/main.yml | 4 +- README.md | 17 +++++---- src/api/controllers/authController.ts | 26 ++++++++++--- src/api/routes/userRoute.ts | 1 - src/api/services/userService.ts | 12 +++++- tsconfig.json | 54 +++++++++++---------------- 6 files changed, 62 insertions(+), 52 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 31c45b9..b9c9210 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,8 +5,8 @@ name: Deploy on push on: # Triggers the workflow on push or pull request events but only for the "main" branch push: - branches: [ "main" ] - + branches: ["main"] + # Allows you to run this workflow manually from the Actions tab workflow_dispatch: diff --git a/README.md b/README.md index 14bf73a..7f436af 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,15 @@ Refer to .env.local file and create your own .env file as required # Backup Overview 1. **Backup Existence**: The project has a robust backup system in place to ensure data integrity and availability. -2. **MongoDB Backup**: - - **Scope**: All user accounts, passwords, blogs, and other data (excluding images) are backed up. - - **Frequency**: Backups are performed daily. - - **Storage**: The backups are stored on the server and uploaded to the Telegram channel. +2. **MongoDB Backup**: + - **Scope**: All user accounts, passwords, blogs, and other data (excluding images) are backed up. + - **Frequency**: Backups are performed daily. + - **Storage**: The backups are stored on the server and uploaded to the Telegram channel. 3. **Image Backup**: - - **Scope**: All image data is backed up. - - **Frequency**: Backups are performed twice a month (every 15 days). - - **Storage**: Image backups are stored on the server. - - **Notifications**: Notifications are delivered on the same Telegram channel whenever an image backup is completed. + - **Scope**: All image data is backed up. + - **Frequency**: Backups are performed twice a month (every 15 days). + - **Storage**: Image backups are stored on the server. + - **Notifications**: Notifications are delivered on the same Telegram channel whenever an image backup is completed. ## Accessing Server Backups @@ -19,6 +19,7 @@ To access server backups, log in using the following credentials: - **Username**: dvishal485 - Managed via cron jobs + ```bash crontab -e ``` diff --git a/src/api/controllers/authController.ts b/src/api/controllers/authController.ts index 8f7145d..a442273 100644 --- a/src/api/controllers/authController.ts +++ b/src/api/controllers/authController.ts @@ -263,7 +263,7 @@ export const login = asyncErrorHandler(async (req, res, next) => { /** * @description Adds user list to users database. - * @route POST /post-add-users + * @route POST /add-members * @param req - The HTTP request object. * @param res - The HTTP response object. * @param next - The next middleware function in the stack. @@ -273,6 +273,7 @@ export const login = asyncErrorHandler(async (req, res, next) => { * @returns data - Contains the data added to the users database. * @howItWorks * - Retrieves the array of users from `req.params.users`. + * - Checks for any duplicate email and returns the list of duplicate email found * - Hashes all the password being added. * - adds all the data to users models */ @@ -280,16 +281,29 @@ export const login = asyncErrorHandler(async (req, res, next) => { export const postBulkUserController = asyncErrorHandler( async (req, res, next) => { const usersData = req.body.users; - if (!Array.isArray(usersData)) { - return res.status(400).json({ error: "user data must be an array" }); + return res.status(400).json({ error: "User data must be an array" }); } - const userDocsInserted = await UserService.createNewUsers(usersData); + const { createdUsers, existingUsers } = + await UserService.createNewUsers(usersData); + + if (existingUsers.length > 0) { + return res.status(StatusCode.CONFLICT).json({ + message: + createdUsers.length > 0 + ? "Some users already exists" + : "No new user created all were duplicate", + data: { + createdUsers: createdUsers, + existingUsers: existingUsers, + }, + }); + } res.status(StatusCode.OK).json({ - message: "User Data successfully inserted", - data: userDocsInserted, + message: "User Data inserted successfully", + data: createdUsers, }); }, ); diff --git a/src/api/routes/userRoute.ts b/src/api/routes/userRoute.ts index 3334302..44ba5bc 100644 --- a/src/api/routes/userRoute.ts +++ b/src/api/routes/userRoute.ts @@ -12,7 +12,6 @@ import { import { protect } from "../middlewares/authMiddleware"; import protected_route from "../middlewares/permsMiddlewareInit"; import Permission from "@static/types/permissions"; -import { create } from "domain"; const router = express.Router(); diff --git a/src/api/services/userService.ts b/src/api/services/userService.ts index 478aadb..bf9ff8e 100644 --- a/src/api/services/userService.ts +++ b/src/api/services/userService.ts @@ -88,9 +88,17 @@ export const createNewUser = async ( }; export const createNewUsers = async (users: Array) => { - const createdUsers: HydratedDocument[] = []; + const incomingEmails = users.map((user) => user.email); + const existingUsers = await User.find({ email: { $in: incomingEmails } }); + const existingEmails = existingUsers.map((user) => user.email); + + console.log(existingEmails); + for (const user of users) { + if (existingEmails.includes(user.email)) { + continue; + } const password: string = generateRandomPassword(7); const hashed_password: string = await bcrypt.hash(password, 10); const newUser = await User.create({ @@ -101,5 +109,5 @@ export const createNewUsers = async (users: Array) => { await reg_mail.sendTo(newUser.email); createdUsers.push(newUser); } - return createdUsers; + return { createdUsers, existingUsers }; }; diff --git a/tsconfig.json b/tsconfig.json index 6747728..9672589 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,35 +1,23 @@ { - "compilerOptions": { - "module": "NodeNext", - "moduleResolution": "nodenext", - "target": "ESNext", - "sourceMap": false, - "outDir": "dist", - "allowJs": false, - "strictNullChecks": true, - "typeRoots": [ - "./src/types", - "./node_modules/@types" - ], - "baseUrl": ".", - "paths": { // Adjust based on your project structure - "@/*": [ - "./src/*" - ], - "@static/*": [ - "./src/commonlib/*" - ] - }, - "resolveJsonModule": true + "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "nodenext", + "target": "ESNext", + "sourceMap": false, + "outDir": "dist", + "allowJs": false, + "strictNullChecks": true, + "typeRoots": ["./src/types", "./node_modules/@types"], + "baseUrl": ".", + "paths": { + // Adjust based on your project structure + "@/*": ["./src/*"], + "@static/*": ["./src/commonlib/*"] }, - "ts-node": { - "require": [ - "tsconfig-paths/register" - ] - }, - "exclude": [ - "node_modules", - "dist", - "src/scripts" - ], -} \ No newline at end of file + "resolveJsonModule": true + }, + "ts-node": { + "require": ["tsconfig-paths/register"] + }, + "exclude": ["node_modules", "dist", "src/scripts"] +} From 9ba421465150e6689ba923173f0bbbc130dbd543 Mon Sep 17 00:00:00 2001 From: Shobhit Tiwari <122107079+Shobhit141141@users.noreply.github.com> Date: Sat, 6 Sep 2025 20:46:49 +0530 Subject: [PATCH 19/19] refactor: improve response messages in postBulkUserController for user creation --- src/api/controllers/authController.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/controllers/authController.ts b/src/api/controllers/authController.ts index a442273..d67f734 100644 --- a/src/api/controllers/authController.ts +++ b/src/api/controllers/authController.ts @@ -292,11 +292,11 @@ export const postBulkUserController = asyncErrorHandler( return res.status(StatusCode.CONFLICT).json({ message: createdUsers.length > 0 - ? "Some users already exists" - : "No new user created all were duplicate", + ? "Some users were added, but some already exist." + : "All provided users already exist.", data: { - createdUsers: createdUsers, - existingUsers: existingUsers, + createdUsers, + existingUsers, }, }); }