From 5572247d9443d57421fcfadac0823016818ae483 Mon Sep 17 00:00:00 2001 From: kjgilder Date: Sun, 27 Oct 2024 16:58:58 -0500 Subject: [PATCH 1/6] updated user endpoint --- api/package.json | 11 +++-- api/src/routes/index.ts | 6 ++- api/src/routes/user.ts | 90 +++++++++++++++++++++++++++++++++++++++-- api/tsconfig.json | 5 ++- 4 files changed, 100 insertions(+), 12 deletions(-) diff --git a/api/package.json b/api/package.json index f5156f4..1d31e01 100644 --- a/api/package.json +++ b/api/package.json @@ -2,11 +2,11 @@ "name": "api", "version": "1.0.0", "description": "", - "main": "src/index.ts", + "main": "src/index.js", "scripts": { "build": "tsc", - "start": "node src/index.ts", - "dev": "nodemon ./src/server.ts", + "start": "node dist/index.js", + "dev": "ts-node-dev --respawn src/routes/index.ts", "test": "echo \"Error: no test specified\" && exit 1", "prettier": "prettier --single-quote --write 'src/**/*.{js,ts}'", "format": "prettier --check" @@ -15,13 +15,11 @@ "author": "", "license": "ISC", "dependencies": { - "axios": "^1.7.7", "cors": "^2.8.5", "dotenv": "^16.4.5", - "express": "^4.21.1", + "express": "^4.21.0", "mongodb": "^6.9.0", "mongoose": "^8.4.1", - "nodemon": "^3.1.7", "ts-node-dev": "^2.0.0", "uuid": "^10.0.0" }, @@ -34,3 +32,4 @@ "typescript": "^5.6.2" } } + diff --git a/api/src/routes/index.ts b/api/src/routes/index.ts index b6bf883..f30ccaa 100644 --- a/api/src/routes/index.ts +++ b/api/src/routes/index.ts @@ -1,8 +1,11 @@ import user from "./user" +// import workshops from "./workshops" + +// export { workshops } export { user } -// import express, { Request, Response, Application } from "express" +//import express, { Request, Response, Application } from "express" // import cors from "cors" // import dbConnect from "./config/dbConnect" // import mongoose from "mongoose" @@ -38,3 +41,4 @@ export { user } // app.listen(port, () => { // console.log(`Server running at http://localhost:${port}`) // }) + diff --git a/api/src/routes/user.ts b/api/src/routes/user.ts index 5ef6cc8..d941d6d 100644 --- a/api/src/routes/user.ts +++ b/api/src/routes/user.ts @@ -1,12 +1,94 @@ import express from "express" +import mongoose from "mongoose" const router = express.Router() -const axios = require("axios").default -router.post("/test", async (req: any, res: any) => { - console.log("Received group data:") +// MongoDB connection +const mongoURI = "mongodb+srv://kjgilder:2htuyRZ09zyS1m0R@pwwusers.8ssyv.mongodb.net/?retryWrites=true&w=majority&appName=PWWUsers" +mongoose.connect(mongoURI) + .then(() => console.log("Connected to MongoDB")) + .catch((error) => console.error("Failed to connect to MongoDB:", error)) - return res.status(200).json({}) +// User schema definition +const userSchema = new mongoose.Schema({ + firstName: String, + lastName: String, + username: String, + email: String, + role: { type: String, enum: ["mentor", "mentee", "admin"], required: true }, + workshopIDs: [String], // For mentors only + menteeInfo: [String], // For mentors only + meetingSchedule: [String], // For mentees only + mentorData: String, // For mentees only + pairings: [[String]] // For admins only, array of pairs of strings +}) + +const User = mongoose.model("User", userSchema) + +// Route to create a new user +router.post("/create-user", async (req: any, res: any) => { + const { firstName, lastName, username, email, role, workshopIDs, menteeInfo, meetingSchedule, mentorData, pairings } = req.body; + + if (!firstName || !lastName || !username || !email || !role) { + return res.status(400).json({ message: "Missing required fields" }); + } + + // Create a new user based on role + const newUser = new User({ + firstName, + lastName, + username, + email, + role, + workshopIDs: role === "mentor" ? workshopIDs : undefined, + menteeInfo: role === "mentor" ? menteeInfo : undefined, + meetingSchedule: role === "mentee" ? meetingSchedule : undefined, + mentorData: role === "mentee" ? mentorData : undefined, + pairings: role === "admin" ? pairings : undefined + }) + + try { + const savedUser = await newUser.save(); + res.status(201).json({ message: "User created successfully", user: savedUser }); + } catch (error) { + res.status(500).json({ message: "Failed to create user", error }); + } }) export default router + + +// import express from "express" +// +// const router = express.Router() +// const axios = require("axios").default +// +// router.post("/create-group", async (req, res) => { +// const { groupName, groupMembers } = req.body +// +// console.log("Received group data:", req.body) +// +// // Validate request body +// if (!groupName || !groupMembers) { +// return res.status(400).json({ +// message: "Invalid data. Please provide group name and group members.", +// }) +// } +// +// // Log the received data for debugging +// console.log("Received group data:", { +// groupName, +// groupMembers, +// }) +// +// // Create a new group +// const response = await axios.post("http://localhost:3001/api/group", { +// groupName, +// groupMembers, +// }) +// +// return res.status(response.status).json(response.data) +// }) +// +// export default router + diff --git a/api/tsconfig.json b/api/tsconfig.json index 6a6679e..d8dc2d4 100644 --- a/api/tsconfig.json +++ b/api/tsconfig.json @@ -107,6 +107,9 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "moduleResolution": "node", + "typeRoots": ["./node_modules/@types"] } } + From 7dd384f87dff8efb0cbf61c819e7ff687b643212 Mon Sep 17 00:00:00 2001 From: kjgilder Date: Mon, 28 Oct 2024 10:49:24 -0500 Subject: [PATCH 2/6] Update 2 for mongo user endpoint --- .gitignore | 1 + api/.env | 2 +- api/package-lock.json | 313 +---------------------------------------- api/src/routes/user.ts | 8 +- 4 files changed, 7 insertions(+), 317 deletions(-) diff --git a/.gitignore b/.gitignore index 8145d0e..e35094d 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ # misc .DS_Store +.env .env.local .env.development.local .env.test.local diff --git a/api/.env b/api/.env index d32fc87..7383386 100644 --- a/api/.env +++ b/api/.env @@ -1 +1 @@ -MONGO_URI=mongodb+srv://User2:kanersdoghouse@bare-bones.pxrwg.mongodb.net/FlatFairDB?retryWrites=true&w=majority&appName=Bare-Bones +MONGO_URI=mongodb+srv://kjgilder:2htuyRZ09zyS1m0R@pwwusers.8ssyv.mongodb.net/?retryWrites=true&w=majority&appName=PWWUsers diff --git a/api/package-lock.json b/api/package-lock.json index 69cedcd..85b4154 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -9,13 +9,11 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "axios": "^1.7.7", "cors": "^2.8.5", "dotenv": "^16.4.5", - "express": "^4.21.1", + "express": "^4.21.0", "mongodb": "^6.9.0", "mongoose": "^8.4.1", - "nodemon": "^3.1.7", "ts-node-dev": "^2.0.0", "uuid": "^10.0.0" }, @@ -279,21 +277,6 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" - }, - "node_modules/axios": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -415,17 +398,6 @@ "fsevents": "~2.3.2" } }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -504,14 +476,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -670,38 +634,6 @@ "node": ">= 0.8" } }, - "node_modules/follow-redirects": { - "version": "1.15.9", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", - "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, - "node_modules/form-data": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", - "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -804,14 +736,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "engines": { - "node": ">=4" - } - }, "node_modules/has-property-descriptors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", @@ -882,11 +806,6 @@ "node": ">=0.10.0" } }, - "node_modules/ignore-by-default": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", - "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==" - }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -1242,54 +1161,6 @@ "node": ">= 0.6" } }, - "node_modules/nodemon": { - "version": "3.1.7", - "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.7.tgz", - "integrity": "sha512-hLj7fuMow6f0lbB0cD14Lz2xNjwsyruH251Pk4t/yIitCFJbmY1myuLlHm/q06aST4jg6EgAh74PIBBrRqpVAQ==", - "dependencies": { - "chokidar": "^3.5.2", - "debug": "^4", - "ignore-by-default": "^1.0.1", - "minimatch": "^3.1.2", - "pstree.remy": "^1.1.8", - "semver": "^7.5.3", - "simple-update-notifier": "^2.0.0", - "supports-color": "^5.5.0", - "touch": "^3.1.0", - "undefsafe": "^2.0.5" - }, - "bin": { - "nodemon": "bin/nodemon.js" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/nodemon" - } - }, - "node_modules/nodemon/node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", - "dependencies": { - "ms": "^2.1.3" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/nodemon/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" - }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -1401,16 +1272,6 @@ "node": ">= 0.10" } }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" - }, - "node_modules/pstree.remy": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", - "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==" - }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -1518,17 +1379,6 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, - "node_modules/semver": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", - "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/send": { "version": "0.19.0", "resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz", @@ -1622,17 +1472,6 @@ "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==" }, - "node_modules/simple-update-notifier": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", - "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", - "dependencies": { - "semver": "^7.5.3" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -1682,17 +1521,6 @@ "node": ">=0.10.0" } }, - "node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/supports-preserve-symlinks-flag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", @@ -1723,14 +1551,6 @@ "node": ">=0.6" } }, - "node_modules/touch": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz", - "integrity": "sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==", - "bin": { - "nodetouch": "bin/nodetouch.js" - } - }, "node_modules/tr46": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/tr46/-/tr46-4.1.1.tgz", @@ -1860,11 +1680,6 @@ "node": ">=14.17" } }, - "node_modules/undefsafe": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", - "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==" - }, "node_modules/undici-types": { "version": "6.19.8", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", @@ -2184,21 +1999,6 @@ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, - "asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" - }, - "axios": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", - "requires": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -2287,14 +2087,6 @@ "readdirp": "~3.6.0" } }, - "combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "requires": { - "delayed-stream": "~1.0.0" - } - }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2355,11 +2147,6 @@ "gopd": "^1.0.1" } }, - "delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" - }, "depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -2481,21 +2268,6 @@ "unpipe": "~1.0.0" } }, - "follow-redirects": { - "version": "1.15.9", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", - "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==" - }, - "form-data": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", - "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - } - }, "forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -2563,11 +2335,6 @@ "get-intrinsic": "^1.1.3" } }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==" - }, "has-property-descriptors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", @@ -2614,11 +2381,6 @@ "safer-buffer": ">= 2.1.2 < 3" } }, - "ignore-by-default": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", - "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==" - }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -2826,38 +2588,6 @@ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" }, - "nodemon": { - "version": "3.1.7", - "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.7.tgz", - "integrity": "sha512-hLj7fuMow6f0lbB0cD14Lz2xNjwsyruH251Pk4t/yIitCFJbmY1myuLlHm/q06aST4jg6EgAh74PIBBrRqpVAQ==", - "requires": { - "chokidar": "^3.5.2", - "debug": "^4", - "ignore-by-default": "^1.0.1", - "minimatch": "^3.1.2", - "pstree.remy": "^1.1.8", - "semver": "^7.5.3", - "simple-update-notifier": "^2.0.0", - "supports-color": "^5.5.0", - "touch": "^3.1.0", - "undefsafe": "^2.0.5" - }, - "dependencies": { - "debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", - "requires": { - "ms": "^2.1.3" - } - }, - "ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" - } - } - }, "normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -2929,16 +2659,6 @@ "ipaddr.js": "1.9.1" } }, - "proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" - }, - "pstree.remy": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", - "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==" - }, "punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -3004,11 +2724,6 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, - "semver": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", - "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==" - }, "send": { "version": "0.19.0", "resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz", @@ -3086,14 +2801,6 @@ "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==" }, - "simple-update-notifier": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", - "integrity": "sha512-a2B9Y0KlNXl9u/vsW6sTIu9vGEpfKu2wRV6l1H3XEas/0gUIzGzBoP/IouTcUQbm9JWZLH3COxyn03TYlFax6w==", - "requires": { - "semver": "^7.5.3" - } - }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -3131,14 +2838,6 @@ "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", "integrity": "sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==" }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "requires": { - "has-flag": "^3.0.0" - } - }, "supports-preserve-symlinks-flag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", @@ -3157,11 +2856,6 @@ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" }, - "touch": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.1.tgz", - "integrity": "sha512-r0eojU4bI8MnHr8c5bNo7lJDdI2qXlWWJk6a9EAFG7vbhTjElYhBVS3/miuE0uOuoLdb8Mc/rVfsmm6eo5o9GA==" - }, "tr46": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/tr46/-/tr46-4.1.1.tgz", @@ -3237,11 +2931,6 @@ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==" }, - "undefsafe": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", - "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==" - }, "undici-types": { "version": "6.19.8", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", diff --git a/api/src/routes/user.ts b/api/src/routes/user.ts index d941d6d..3114e60 100644 --- a/api/src/routes/user.ts +++ b/api/src/routes/user.ts @@ -20,14 +20,14 @@ const userSchema = new mongoose.Schema({ menteeInfo: [String], // For mentors only meetingSchedule: [String], // For mentees only mentorData: String, // For mentees only - pairings: [[String]] // For admins only, array of pairs of strings + //pairings: [[String]] // For admins only, array of pairs of strings }) const User = mongoose.model("User", userSchema) // Route to create a new user router.post("/create-user", async (req: any, res: any) => { - const { firstName, lastName, username, email, role, workshopIDs, menteeInfo, meetingSchedule, mentorData, pairings } = req.body; + const { firstName, lastName, username, email, role, workshopIDs, menteeInfo, meetingSchedule, mentorData } = req.body; if (!firstName || !lastName || !username || !email || !role) { return res.status(400).json({ message: "Missing required fields" }); @@ -44,14 +44,14 @@ router.post("/create-user", async (req: any, res: any) => { menteeInfo: role === "mentor" ? menteeInfo : undefined, meetingSchedule: role === "mentee" ? meetingSchedule : undefined, mentorData: role === "mentee" ? mentorData : undefined, - pairings: role === "admin" ? pairings : undefined + //pairings: role === "admin" ? pairings : undefined }) try { const savedUser = await newUser.save(); res.status(201).json({ message: "User created successfully", user: savedUser }); } catch (error) { - res.status(500).json({ message: "Failed to create user", error }); + res.status(400).json({ message: "Failed to create user", error }); } }) From 8402e02ace7d84a376a3db32e9214647555c04e0 Mon Sep 17 00:00:00 2001 From: kjgilder Date: Mon, 28 Oct 2024 12:54:15 -0500 Subject: [PATCH 3/6] Added a workshop endpoint --- api/src/routes/index.ts | 3 ++- api/src/routes/workshopid.ts | 42 ++++++++++++++++++++++++++++++++++++ api/src/server.ts | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 api/src/routes/workshopid.ts diff --git a/api/src/routes/index.ts b/api/src/routes/index.ts index f30ccaa..ded019c 100644 --- a/api/src/routes/index.ts +++ b/api/src/routes/index.ts @@ -1,9 +1,10 @@ import user from "./user" +import workshopid from "./workshopid" // import workshops from "./workshops" // export { workshops } -export { user } +export { user, workshopid } //import express, { Request, Response, Application } from "express" // import cors from "cors" diff --git a/api/src/routes/workshopid.ts b/api/src/routes/workshopid.ts new file mode 100644 index 0000000..3788a87 --- /dev/null +++ b/api/src/routes/workshopid.ts @@ -0,0 +1,42 @@ +import express from "express" +import mongoose from "mongoose" + +const router = express.Router() + +// MongoDB connection +const mongoURI = "mongodb+srv://kjgilder:2htuyRZ09zyS1m0R@pwwusers.8ssyv.mongodb.net/?retryWrites=true&w=majority&appName=PWWUsers" +mongoose.connect(mongoURI) + .then(() => console.log("Connected to MongoDB")) + .catch((error) => console.error("Failed to connect to MongoDB:", error)) + +// Workshop schema definition (name and S3 bucket ID) +const workshopIDSchema = new mongoose.Schema({ + name: String, + s3ID: String +}) + +const WorkshopID = mongoose.model("WorkshopID", workshopIDSchema) + +// Route to create a new workshop +router.post("/create-workshopID", async (req: any, res: any) => { + const { name, s3ID } = req.body; + + if (!name || !s3ID ) { + return res.status(400).json({ message: "Missing required fields" }); + } + + // Create a new workshop + const newWorkshop = new WorkshopID({ + name, + s3ID + }) + + try { + const savedWorkshop = await newWorkshop.save(); + res.status(201).json({ message: "Workshop created successfully", WorkshopID: savedWorkshop }); + } catch (error) { + res.status(400).json({ message: "Failed to create workshop", error }); + } +}) + +export default router \ No newline at end of file diff --git a/api/src/server.ts b/api/src/server.ts index 7543d60..0188b10 100644 --- a/api/src/server.ts +++ b/api/src/server.ts @@ -12,5 +12,6 @@ app.use(bodyParser.json()) app.use(bodyParser.urlencoded({ extended: true })) app.use("/user", routes.user) +app.use("/workshopid", routes.workshopid) app.listen(process.env.PORT || 8000, () => console.log("Server running...")) From 7b8bd6eb90187dc9e6487f396a4047b6cfb2bd13 Mon Sep 17 00:00:00 2001 From: charlotteconze <85513920+charlotteconze@users.noreply.github.com> Date: Sun, 3 Nov 2024 15:15:22 -0600 Subject: [PATCH 4/6] Minor tweaks --- api/src/config/db.ts | 23 +++++----- api/src/routes/index.ts | 4 +- api/src/routes/user.ts | 45 ++++++++++++------- api/src/routes/{workshopid.ts => workshop.ts} | 29 ++++++------ api/src/server.ts | 2 + 5 files changed, 57 insertions(+), 46 deletions(-) rename api/src/routes/{workshopid.ts => workshop.ts} (52%) diff --git a/api/src/config/db.ts b/api/src/config/db.ts index 6c21f0e..3e19c51 100644 --- a/api/src/config/db.ts +++ b/api/src/config/db.ts @@ -1,18 +1,17 @@ -import mongoose from 'mongoose' -import dotenv from 'dotenv' -import path from 'path' +import mongoose from "mongoose" +import dotenv from "dotenv" +import path from "path" -dotenv.config({ path: path.resolve(__dirname, '../../.env') }); +dotenv.config({ path: path.resolve(__dirname, "../../.env") }) // Connect to MongoDB const dbConnect = async () => { - try { - await mongoose.connect(process.env.MONGO_URI as string, { - }) - console.log("Connected to MongoDB") - } catch (error) { - console.error(error) - } + try { + await mongoose.connect(process.env.MONGO_URI as string, {}) + console.log("Connected to MongoDB") + } catch (error) { + console.error(error) + } } -export default dbConnect \ No newline at end of file +export default dbConnect diff --git a/api/src/routes/index.ts b/api/src/routes/index.ts index ded019c..056e826 100644 --- a/api/src/routes/index.ts +++ b/api/src/routes/index.ts @@ -1,8 +1,7 @@ import user from "./user" -import workshopid from "./workshopid" +import workshopid from "./workshop" // import workshops from "./workshops" - // export { workshops } export { user, workshopid } @@ -42,4 +41,3 @@ export { user, workshopid } // app.listen(port, () => { // console.log(`Server running at http://localhost:${port}`) // }) - diff --git a/api/src/routes/user.ts b/api/src/routes/user.ts index 7387c43..cbc829b 100644 --- a/api/src/routes/user.ts +++ b/api/src/routes/user.ts @@ -1,13 +1,11 @@ import express from "express" import mongoose from "mongoose" +import dbConnect from "../config/db" const router = express.Router() -// MongoDB connection -const mongoURI = "mongodb+srv://kjgilder:2htuyRZ09zyS1m0R@pwwusers.8ssyv.mongodb.net/?retryWrites=true&w=majority&appName=PWWUsers" -mongoose.connect(mongoURI) - .then(() => console.log("Connected to MongoDB")) - .catch((error) => console.error("Failed to connect to MongoDB:", error)) +// Call the dbConnect function to connect to MongoDB +dbConnect() // User schema definition const userSchema = new mongoose.Schema({ @@ -16,20 +14,30 @@ const userSchema = new mongoose.Schema({ username: String, email: String, role: { type: String, enum: ["mentor", "mentee", "admin"], required: true }, - workshopIDs: [String], // For mentors only - menteeInfo: [String], // For mentors only - meetingSchedule: [String], // For mentees only - mentorData: String, // For mentees only + workshopIDs: [String], // For mentors only + menteeInfo: [String], // For mentors only + meetingSchedule: [String], // For mentees only + mentorData: String, // For mentees only }) const User = mongoose.model("User", userSchema) // Route to create a new user router.post("/create-user", async (req: any, res: any) => { - const { firstName, lastName, username, email, role, workshopIDs, menteeInfo, meetingSchedule, mentorData } = req.body; + const { + firstName, + lastName, + username, + email, + role, + workshopIDs, + menteeInfo, + meetingSchedule, + mentorData, + } = req.body if (!firstName || !lastName || !username || !email || !role) { - return res.status(400).json({ message: "Missing required fields" }); + return res.status(400).json({ message: "Missing required fields" }) } // Create a new user based on role @@ -46,18 +54,21 @@ router.post("/create-user", async (req: any, res: any) => { }) try { - const savedUser = await newUser.save(); - res.status(201).json({ message: "User created successfully", user: savedUser }); + const savedUser = await newUser.save() + res + .status(201) + .json({ message: "User created successfully", user: savedUser }) } catch (error) { - res.status(400).json({ message: "Failed to create user", error }); + res.status(400).json({ message: "Failed to create user", error }) } }) +// Test route to check if the API is working router.post("/test", async (req: any, res: any) => { console.log("Received group data:") - const {name} = req.body; + const { name } = req.body - return res.status(200).json(name) + return res.status(200).json({ name }) }) -export default router \ No newline at end of file +export default router diff --git a/api/src/routes/workshopid.ts b/api/src/routes/workshop.ts similarity index 52% rename from api/src/routes/workshopid.ts rename to api/src/routes/workshop.ts index 3788a87..5e045bb 100644 --- a/api/src/routes/workshopid.ts +++ b/api/src/routes/workshop.ts @@ -1,42 +1,43 @@ import express from "express" import mongoose from "mongoose" +import dbConnect from "../config/db" // Import the dbConnect function const router = express.Router() -// MongoDB connection -const mongoURI = "mongodb+srv://kjgilder:2htuyRZ09zyS1m0R@pwwusers.8ssyv.mongodb.net/?retryWrites=true&w=majority&appName=PWWUsers" -mongoose.connect(mongoURI) - .then(() => console.log("Connected to MongoDB")) - .catch((error) => console.error("Failed to connect to MongoDB:", error)) +// Call the dbConnect function to connect to MongoDB +dbConnect() // Workshop schema definition (name and S3 bucket ID) const workshopIDSchema = new mongoose.Schema({ name: String, - s3ID: String + s3ID: String, }) const WorkshopID = mongoose.model("WorkshopID", workshopIDSchema) // Route to create a new workshop router.post("/create-workshopID", async (req: any, res: any) => { - const { name, s3ID } = req.body; + const { name, s3ID } = req.body - if (!name || !s3ID ) { - return res.status(400).json({ message: "Missing required fields" }); + if (!name || !s3ID) { + return res.status(400).json({ message: "Missing required fields" }) } // Create a new workshop const newWorkshop = new WorkshopID({ name, - s3ID + s3ID, }) try { - const savedWorkshop = await newWorkshop.save(); - res.status(201).json({ message: "Workshop created successfully", WorkshopID: savedWorkshop }); + const savedWorkshop = await newWorkshop.save() + res.status(201).json({ + message: "Workshop created successfully", + WorkshopID: savedWorkshop, + }) } catch (error) { - res.status(400).json({ message: "Failed to create workshop", error }); + res.status(400).json({ message: "Failed to create workshop", error }) } }) -export default router \ No newline at end of file +export default router diff --git a/api/src/server.ts b/api/src/server.ts index 0188b10..a601f88 100644 --- a/api/src/server.ts +++ b/api/src/server.ts @@ -14,4 +14,6 @@ app.use(bodyParser.urlencoded({ extended: true })) app.use("/user", routes.user) app.use("/workshopid", routes.workshopid) +connectDB() + app.listen(process.env.PORT || 8000, () => console.log("Server running...")) From dc8e89f5cf2100638a1d90740bb8f54ca2732c28 Mon Sep 17 00:00:00 2001 From: kjgilder Date: Sun, 3 Nov 2024 16:28:52 -0600 Subject: [PATCH 5/6] Fixed package.json --- api/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/package.json b/api/package.json index cd8bfbd..b54317c 100644 --- a/api/package.json +++ b/api/package.json @@ -2,11 +2,11 @@ "name": "api", "version": "1.0.0", "description": "", - "main": "src/index.js", + "main": "src/index.ts", "scripts": { "build": "tsc", - "start": "node dist/index.js", - "dev": "ts-node-dev --respawn src/routes/index.ts", + "start": "node src/index.ts", + "dev": "nodemon ./src/server.ts", "test": "echo \"Error: no test specified\" && exit 1", "prettier": "prettier --single-quote --write 'src/**/*.{js,ts}'", "format": "prettier --check" From 5d4099f9053f26dc5404aeae1234fbb43ac6145d Mon Sep 17 00:00:00 2001 From: Katelyn Gildersleeve <155999260+kjgilder@users.noreply.github.com> Date: Sun, 3 Nov 2024 17:27:40 -0600 Subject: [PATCH 6/6] Delete api/.env --- api/.env | 1 - 1 file changed, 1 deletion(-) delete mode 100644 api/.env diff --git a/api/.env b/api/.env deleted file mode 100644 index 7383386..0000000 --- a/api/.env +++ /dev/null @@ -1 +0,0 @@ -MONGO_URI=mongodb+srv://kjgilder:2htuyRZ09zyS1m0R@pwwusers.8ssyv.mongodb.net/?retryWrites=true&w=majority&appName=PWWUsers