From 9149bba8688582cc48d6f2a504809bfb33b20c43 Mon Sep 17 00:00:00 2001 From: JBB0807 <104856796+JBB0807@users.noreply.github.com> Date: Thu, 1 May 2025 16:07:55 -0700 Subject: [PATCH] added password hashing --- assignment-db-service/.env.development | 14 ++ assignment-db-service/{dev.env => .env.test} | 2 + assignment-db-service/app.js | 54 ++++---- assignment-db-service/package-lock.json | 123 ++++++++++++++++++ assignment-db-service/package.json | 5 +- assignment-service/.env.development | 6 + assignment-service/.env.test | 6 + assignment-service/package-lock.json | 110 ++++++++++++++++ assignment-service/package.json | 6 +- assignment-service/routes/InstructorRouter.js | 105 +++++++++------ auth-service/{dev.env => .env.development} | 0 compose.yaml | 8 +- user-db-service/{dev.env => .env.development} | 0 13 files changed, 364 insertions(+), 75 deletions(-) create mode 100644 assignment-db-service/.env.development rename assignment-db-service/{dev.env => .env.test} (97%) create mode 100644 assignment-service/.env.development create mode 100644 assignment-service/.env.test rename auth-service/{dev.env => .env.development} (100%) rename user-db-service/{dev.env => .env.development} (100%) diff --git a/assignment-db-service/.env.development b/assignment-db-service/.env.development new file mode 100644 index 0000000..d370b34 --- /dev/null +++ b/assignment-db-service/.env.development @@ -0,0 +1,14 @@ +NODE_ENV=development + +# Environment variables declared in this file are automatically made available to Prisma. +# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema + +# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. +# See the documentation for all the connection string options: https://pris.ly/d/connection-strings + +#use this when testing local, remmber to run the proxy command +DATABASE_URL="postgresql://postgres:wly9H8gjjmxYfg1@localhost:15432/postgres?schema=public" + +# DATABASE_URL="postgres://postgres:wly9H8gjjmxYfg1@bytecamp-db.flycast:5432?sslmode=disable" +# DATABASE_URL=postgres://snakebyte:zVB7lgOiKr89dq6@localhost:5432/snakebyte?sslmode=disable +NODE_PORT=3200 diff --git a/assignment-db-service/dev.env b/assignment-db-service/.env.test similarity index 97% rename from assignment-db-service/dev.env rename to assignment-db-service/.env.test index 1e00c54..b464239 100644 --- a/assignment-db-service/dev.env +++ b/assignment-db-service/.env.test @@ -1,3 +1,5 @@ +NODE_ENV=development + # Environment variables declared in this file are automatically made available to Prisma. # See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema diff --git a/assignment-db-service/app.js b/assignment-db-service/app.js index 115c256..09f0055 100644 --- a/assignment-db-service/app.js +++ b/assignment-db-service/app.js @@ -10,8 +10,24 @@ const port = process.env.NODE_PORT || 3000; app.use(express.json()); app.use(express.urlencoded({ extended: true })); +async function encryptPassword(password) { + if (!password) { + return null; + } + + return new Promise((resolve, reject) => { + bcrypt.hash(password, 10, (err, hash) => { + if (err) { + reject(err); + } else { + resolve(hash); + } + }); + }); +} + //function to conver req.body to assignment -function convertToAssignment(req) { +async function convertToAssignment(req) { const { campid, programid, @@ -24,7 +40,8 @@ function convertToAssignment(req) { instructorid } = req.body; - // const hashedPassword = await bcrypt.hash(Password, 10); + const hashPassword = await encryptPassword(req.body.password); + return { campid: campid, programid: programid, @@ -33,8 +50,7 @@ function convertToAssignment(req) { originalfile: originalfile, editablefile: editablefile, assignmenturl: assignmenturl, - // passwordhash: hashedpassword, - passwordhash: password, + passwordhash: hashPassword, instructorid: instructorid, }; } @@ -44,25 +60,11 @@ app.post("/assignments", async (req, res) => { try { console.log("Request body:", req.body); - // const { - // campid, - // programid, - // studentname, - // snakegameid, - // originalfile, - // editablefile, - // assignmenturl, - // password, - // instructorid - // } = req.body; - - // const hashedPassword = await bcrypt.hash(Password, 10); + const assignment = await convertToAssignment(req); const newAssignment = await prisma.assignments.create({ - data: { - ...convertToAssignment(req) - }, + data: assignment, }); - + console.log("Assignment created successfully:", newAssignment); res.json({ @@ -119,17 +121,11 @@ app.get("/assignments/:id", async (req, res) => { app.put("/assignments/:id", async (req, res) => { try { const { id } = req.params; - const data = req.body; - - if (data.password) { - // data.passwordhash = await bcrypt.hash(data.Password, 10); - data.passwordhash = data.password; - delete data.password; - } + const assignment = await convertToAssignment(req); const updatedAssignment = await prisma.assignments.update({ where: { assignmentid: parseInt(id) }, - data, + data: assignment, }); res.json({ diff --git a/assignment-db-service/package-lock.json b/assignment-db-service/package-lock.json index 1f1e538..d88c403 100644 --- a/assignment-db-service/package-lock.json +++ b/assignment-db-service/package-lock.json @@ -10,6 +10,9 @@ "express": "^5.1.0", "nodemon": "^3.1.9", "prisma": "^6.1.0" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } }, "node_modules/@mapbox/node-pre-gyp": { @@ -377,6 +380,21 @@ "node": ">=6.6.0" } }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/debug": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", @@ -418,6 +436,45 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "16.5.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.5.0.tgz", + "integrity": "sha512-m/C+AwOAr9/W1UOIZUo232ejMNnJAJtYQjUbHoNTBNTJSvqzzDh7vnrei3o3r3m9blf6ZoDkvcw0VmozNRFJxg==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dotenv-cli": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz", + "integrity": "sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cross-spawn": "^7.0.6", + "dotenv": "^16.3.0", + "dotenv-expand": "^10.0.0", + "minimist": "^1.2.6" + }, + "bin": { + "dotenv": "cli.js" + } + }, + "node_modules/dotenv-expand": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz", + "integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -912,6 +969,13 @@ "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "license": "MIT" }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, + "license": "ISC" + }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -999,6 +1063,16 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/minipass": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", @@ -1211,6 +1285,16 @@ "node": ">=0.10.0" } }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/path-to-regexp": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", @@ -1454,6 +1538,29 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "license": "ISC" }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/side-channel": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", @@ -1713,6 +1820,22 @@ "webidl-conversions": "^3.0.0" } }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/wide-align": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", diff --git a/assignment-db-service/package.json b/assignment-db-service/package.json index ca9db41..6724b9c 100644 --- a/assignment-db-service/package.json +++ b/assignment-db-service/package.json @@ -8,6 +8,9 @@ }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "dev": "nodemon app.js" + "dev": "dotenv -e .env.development nodemon app.js" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } } diff --git a/assignment-service/.env.development b/assignment-service/.env.development new file mode 100644 index 0000000..1bc73e5 --- /dev/null +++ b/assignment-service/.env.development @@ -0,0 +1,6 @@ +NODE_ENV=development +#DB_ASSIGNMENT_SERVICE_URL="http://localhost:3000" +DB_ASSIGNMENT_SERVICE_URL="http://localhost:3200" +AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" +ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 +PORT=8082 \ No newline at end of file diff --git a/assignment-service/.env.test b/assignment-service/.env.test new file mode 100644 index 0000000..d39a82f --- /dev/null +++ b/assignment-service/.env.test @@ -0,0 +1,6 @@ +NODE_ENV=development +#DB_ASSIGNMENT_SERVICE_URL="http://localhost:3000" +DB_ASSIGNMENT_SERVICE_URL="http://js-assignment-db-service:3200" +AUTH_SESSION_KEY="f3f4d8e6b17a4b3abdc8e9a2c0457aaf91c0d5f6e3b7a9c8df624bd71ea35f42" +ACCEPTED_ORIGINS=http://localhost:3000,http://localhost:8081,http://localhost:3001,http://localhost:5173 +PORT=8082 \ No newline at end of file diff --git a/assignment-service/package-lock.json b/assignment-service/package-lock.json index 3dff094..683f7be 100644 --- a/assignment-service/package-lock.json +++ b/assignment-service/package-lock.json @@ -17,6 +17,9 @@ "express-session": "^1.18.1", "nodemon": "^3.1.9", "passport": "^0.7.0" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } }, "node_modules/@mapbox/node-pre-gyp": { @@ -393,6 +396,21 @@ "node": ">= 0.10" } }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -453,6 +471,32 @@ "url": "https://dotenvx.com" } }, + "node_modules/dotenv-cli": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/dotenv-cli/-/dotenv-cli-8.0.0.tgz", + "integrity": "sha512-aLqYbK7xKOiTMIRf1lDPbI+Y+Ip/wo5k3eyp6ePysVaSqbyxjyK3dK35BTxG+rmd7djf5q2UPs4noPNH+cj0Qw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cross-spawn": "^7.0.6", + "dotenv": "^16.3.0", + "dotenv-expand": "^10.0.0", + "minimist": "^1.2.6" + }, + "bin": { + "dotenv": "cli.js" + } + }, + "node_modules/dotenv-expand": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz", + "integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -1109,6 +1153,13 @@ "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "license": "MIT" }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, + "license": "ISC" + }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -1196,6 +1247,16 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/minipass": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/minipass/-/minipass-5.0.0.tgz", @@ -1460,6 +1521,16 @@ "node": ">=0.10.0" } }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/path-to-regexp": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.2.0.tgz", @@ -1738,6 +1809,29 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "license": "ISC" }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/side-channel": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", @@ -2018,6 +2112,22 @@ "webidl-conversions": "^3.0.0" } }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/wide-align": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", diff --git a/assignment-service/package.json b/assignment-service/package.json index b0a2b99..365e94e 100644 --- a/assignment-service/package.json +++ b/assignment-service/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "main": "server.js", "scripts": { - "dev": "nodemon server.js" + "dev": "dotenv -e .env.development nodemon server.js" }, "keywords": [], "author": "", @@ -11,11 +11,15 @@ "description": "", "dependencies": { "axios": "^1.8.4", + "bcrypt": "^5.1.1", "cors": "^2.8.5", "dotenv": "^16.5.0", "express": "^5.1.0", "express-session": "^1.18.1", "nodemon": "^3.1.9", "passport": "^0.7.0" + }, + "devDependencies": { + "dotenv-cli": "^8.0.0" } } diff --git a/assignment-service/routes/InstructorRouter.js b/assignment-service/routes/InstructorRouter.js index c3a6d01..ffee372 100644 --- a/assignment-service/routes/InstructorRouter.js +++ b/assignment-service/routes/InstructorRouter.js @@ -2,30 +2,40 @@ const intructorRouter = require("express").Router(); const passport = require("passport"); const axios = require("axios"); -const DB_ASSIGNMENT_SERVICE_URL = process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000"; +const DB_ASSIGNMENT_SERVICE_URL = + process.env.DB_ASSIGNMENT_SERVICE_URL || "http://localhost:3000"; console.log("DB_ASSIGNMENT_SERVICE_URL:", DB_ASSIGNMENT_SERVICE_URL); // This endpoint is for instructors to create a new assignment -intructorRouter.post("/create", - // passport.authenticate("jwt", { session: false }), +intructorRouter.post( + "/create", + // passport.authenticate("jwt", { session: false }), async (req, res) => { - try { - console.log("Creating a new assignment with data:", req.body); - const response = await axios.post(`${DB_ASSIGNMENT_SERVICE_URL}/assignments`, req.body); - console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); - res.status(response.status).json(response.data); - } catch (error) { - console.error("Error creating assignment:", error.message); - res.status(error.response?.status || 500).json({ error: error.message }); + try { + + console.log("Creating a new assignment with data:", req.body); + const response = await axios.post( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments`, + req.body + ); + console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); + res.status(response.status).json(response.data); + } catch (error) { + console.error("Error creating assignment:", error.message); + res.status(error.response?.status || 500).json({ error: error.message }); + } } -}); +); // This endpoint is for instructors to get details of a specific assignment intructorRouter.get("/details/:id", async (req, res) => { try { const assignmentId = req.params.id; console.log("Fetching details for assignmentId:", assignmentId); - const response = await axios.get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`); + const response = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` + ); + console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); } catch (error) { @@ -35,48 +45,63 @@ intructorRouter.get("/details/:id", async (req, res) => { }); // This endpoint is for instructors to get a list of assignments they have created -intructorRouter.get("/list/:id", async (req, res) => { - // if (req.isAuthenticated()) { +intructorRouter.get( + "/list/:id", + // passport.authenticate("jwt", { session: false }), + async (req, res) => { + // if (req.isAuthenticated()) { try { const instructorId = req.params.id; console.log("Fetching assignments for instructorId:", instructorId); // const instructorId = req.user.userid; // Assuming req.user contains the authenticated user - const response = await axios.get(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/instructor/${instructorId}`); + const response = await axios.get( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/instructor/${instructorId}` + ); console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data); res.status(response.status).json(response.data); } catch (error) { res.status(error.response?.status || 500).json({ error: error.message }); } - // } else { - // return res.status(401).json({ error: "Not authenticated" }); - // } - -}); + // } else { + // return res.status(401).json({ error: "Not authenticated" }); + // } + } +); // This endpoint is for instructors to update an assignment -intructorRouter.put("/update/:id", - // passport.authenticate("jwt", { session: false }), +intructorRouter.put( + "/update/:id", + // passport.authenticate("jwt", { session: false }), async (req, res) => { - try { - const assignmentId = req.params.id; - const response = await axios.put(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`, req.body); - res.status(response.status).json(response.data); - } catch (error) { - res.status(error.response?.status || 500).json({ error: error.message }); + try { + const assignmentId = req.params.id; + + const response = await axios.put( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`, + req.body + ); + res.status(response.status).json(response.data); + } catch (error) { + res.status(error.response?.status || 500).json({ error: error.message }); + } } -}); +); // This endpoint is for instructors to delete an assignment -intructorRouter.delete("/delete/:id", - // passport.authenticate("jwt", { session: false }), +intructorRouter.delete( + "/delete/:id", + // passport.authenticate("jwt", { session: false }), async (req, res) => { - try { - const assignmentId = req.params.id; - const response = await axios.delete(`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`); - res.status(response.status).json(response.data); - } catch (error) { - res.status(error.response?.status || 500).json({ error: error.message }); + try { + const assignmentId = req.params.id; + const response = await axios.delete( + `${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}` + ); + res.status(response.status).json(response.data); + } catch (error) { + res.status(error.response?.status || 500).json({ error: error.message }); + } } -}); +); -module.exports = intructorRouter; \ No newline at end of file +module.exports = intructorRouter; diff --git a/auth-service/dev.env b/auth-service/.env.development similarity index 100% rename from auth-service/dev.env rename to auth-service/.env.development diff --git a/compose.yaml b/compose.yaml index 99c6a2d..41c59e6 100644 --- a/compose.yaml +++ b/compose.yaml @@ -11,7 +11,7 @@ services: ports: - "3200:3200" # Expose port to the same host env_file: - - ./assignment-db-service/dev.env + - ./assignment-db-service/.env.development networks: - backend @@ -25,7 +25,7 @@ services: ports: - "8082:8082" # Expose port to the same host env_file: - - ./assignment-service/dev.env + - ./assignment-service/.env.development depends_on: - js-assignment-db-service networks: @@ -41,7 +41,7 @@ services: ports: - "8080:8080" # Expose port to the same host env_file: - - ./auth-service/dev.env + - ./auth-service/.env.development networks: - backend @@ -55,7 +55,7 @@ services: ports: - "3100:3100" # Expose port to the same host env_file: - - ./user-db-service/dev.env + - ./user-db-service/.env.development networks: - backend diff --git a/user-db-service/dev.env b/user-db-service/.env.development similarity index 100% rename from user-db-service/dev.env rename to user-db-service/.env.development