From dc301691c8bc730833aeebc51001bf5cb18258ce Mon Sep 17 00:00:00 2001 From: Gabriele Capezzuto Date: Sat, 24 May 2025 16:42:44 +0200 Subject: [PATCH 01/14] changes to the app.js --- server/app.js | 51 +++-- server/package-lock.json | 407 +++++++++++++++++++++++++++++---------- server/package.json | 5 +- 3 files changed, 342 insertions(+), 121 deletions(-) diff --git a/server/app.js b/server/app.js index dfe51f49..38d628ad 100644 --- a/server/app.js +++ b/server/app.js @@ -1,36 +1,45 @@ +// IMPORTS const express = require("express"); const morgan = require("morgan"); const cookieParser = require("cookie-parser"); -const PORT = 5005; +const cors = require("cors"); +const path = require("path"); -// STATIC DATA -// Devs Team - Import the provided files with JSON data of students and cohorts here: -// ... +const PORT = 5005; +// STATIC DATA - Import JSON data +const students = require("./data/students.json"); +const cohorts = require("./data/cohorts.json"); -// INITIALIZE EXPRESS APP - https://expressjs.com/en/4x/api.html#express +// INITIALIZE EXPRESS APP const app = express(); - // MIDDLEWARE -// Research Team - Set up CORS middleware here: -// ... -app.use(express.json()); -app.use(morgan("dev")); -app.use(express.static("public")); -app.use(express.urlencoded({ extended: false })); -app.use(cookieParser()); - - -// ROUTES - https://expressjs.com/en/starter/basic-routing.html -// Devs Team - Start working on the routes here: -// ... +app.use(cors()); // Enable CORS +app.use(express.json()); // Parse JSON payloads +app.use(morgan("dev")); // Log HTTP requests +app.use(express.static("public")); // Serve static assets +app.use(express.urlencoded({ extended: false })); // Parse URL-encoded bodies +app.use(cookieParser()); // Parse cookies + +// ROUTES + +// Route to serve the API documentation HTML file app.get("/docs", (req, res) => { - res.sendFile(__dirname + "/views/docs.html"); + res.sendFile(path.join(__dirname, "views", "docs.html")); }); +// Route to get all students +app.get("/api/students", (req, res) => { + res.json(students); +}); + +// Route to get all cohorts +app.get("/api/cohorts", (req, res) => { + res.json(cohorts); +}); // START SERVER app.listen(PORT, () => { - console.log(`Server listening on port ${PORT}`); -}); \ No newline at end of file + console.log(`✅ Server is running at http://localhost:${PORT}`); +}); diff --git a/server/package-lock.json b/server/package-lock.json index 23e2f78a..06fc345f 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -10,7 +10,7 @@ "license": "ISC", "dependencies": { "cookie-parser": "^1.4.6", - "express": "^4.18.2", + "express": "^4.21.2", "morgan": "^1.10.0", "nodemon": "^3.0.1" } @@ -79,20 +79,21 @@ } }, "node_modules/body-parser": { - "version": "1.20.1", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", - "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", + "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==", + "license": "MIT", "dependencies": { "bytes": "3.1.2", - "content-type": "~1.0.4", + "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.11.0", - "raw-body": "2.5.1", + "qs": "6.13.0", + "raw-body": "2.5.2", "type-is": "~1.6.18", "unpipe": "1.0.0" }, @@ -125,17 +126,35 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", "engines": { "node": ">= 0.8" } }, - "node_modules/call-bind": { + "node_modules/call-bind-apply-helpers": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", - "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "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": { - "function-bind": "^1.1.1", - "get-intrinsic": "^1.0.2" + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "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.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -187,6 +206,7 @@ "version": "1.0.5", "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", "engines": { "node": ">= 0.6" } @@ -236,68 +256,117 @@ "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/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "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==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", "engines": { "node": ">= 0.8" } }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" }, "node_modules/etag": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", "engines": { "node": ">= 0.6" } }, "node_modules/express": { - "version": "4.18.2", - "resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz", - "integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==", + "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.1", + "body-parser": "1.20.3", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.5.0", + "cookie": "0.7.1", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "2.0.0", - "encodeurl": "~1.0.2", + "encodeurl": "~2.0.0", "escape-html": "~1.0.3", "etag": "~1.8.1", - "finalhandler": "1.2.0", + "finalhandler": "1.3.1", "fresh": "0.5.2", "http-errors": "2.0.0", - "merge-descriptors": "1.0.1", + "merge-descriptors": "1.0.3", "methods": "~1.1.2", "on-finished": "2.4.1", "parseurl": "~1.3.3", - "path-to-regexp": "0.1.7", + "path-to-regexp": "0.1.12", "proxy-addr": "~2.0.7", - "qs": "6.11.0", + "qs": "6.13.0", "range-parser": "~1.2.1", "safe-buffer": "5.2.1", - "send": "0.18.0", - "serve-static": "1.15.0", + "send": "0.19.0", + "serve-static": "1.16.2", "setprototypeof": "1.2.0", "statuses": "2.0.1", "type-is": "~1.6.18", @@ -306,12 +375,17 @@ }, "engines": { "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" } }, "node_modules/express/node_modules/cookie": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", - "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==", + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz", + "integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==", + "license": "MIT", "engines": { "node": ">= 0.6" } @@ -328,12 +402,13 @@ } }, "node_modules/finalhandler": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", - "integrity": "sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.1.tgz", + "integrity": "sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ==", + "license": "MIT", "dependencies": { "debug": "2.6.9", - "encodeurl": "~1.0.2", + "encodeurl": "~2.0.0", "escape-html": "~1.0.3", "on-finished": "2.4.1", "parseurl": "~1.3.3", @@ -356,6 +431,7 @@ "version": "0.5.2", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "license": "MIT", "engines": { "node": ">= 0.6" } @@ -374,24 +450,51 @@ } }, "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/get-intrinsic": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.1.tgz", - "integrity": "sha512-2DcsyfABl+gVHEfCOaTrWgyt+tb6MSEGmKq+kI5HwLbIYgjgmMcV8KQ41uaKz1xxUcn9tJtgFbQUEVcEbd0FYw==", + "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": { - "function-bind": "^1.1.1", - "has": "^1.0.3", - "has-proto": "^1.0.1", - "has-symbols": "^1.0.3" + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/glob-parent": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", @@ -403,15 +506,16 @@ "node": ">= 6" } }, - "node_modules/has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dependencies": { - "function-bind": "^1.1.1" - }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", "engines": { - "node": ">= 0.4.0" + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, "node_modules/has-flag": { @@ -422,10 +526,11 @@ "node": ">=4" } }, - "node_modules/has-proto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", - "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==", + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -433,21 +538,23 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/has-symbols": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", - "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, "engines": { "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" } }, "node_modules/http-errors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "license": "MIT", "dependencies": { "depd": "2.0.0", "inherits": "2.0.4", @@ -463,6 +570,7 @@ "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "license": "MIT", "dependencies": { "safer-buffer": ">= 2.1.2 < 3" }, @@ -478,7 +586,8 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" }, "node_modules/ipaddr.js": { "version": "1.9.1", @@ -537,18 +646,32 @@ "node": ">=10" } }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", "engines": { "node": ">= 0.6" } }, "node_modules/merge-descriptors": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==" + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", + "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } }, "node_modules/methods": { "version": "1.1.2", @@ -562,6 +685,7 @@ "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" }, @@ -701,9 +825,13 @@ } }, "node_modules/object-inspect": { - "version": "1.12.3", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.3.tgz", - "integrity": "sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g==", + "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" + }, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -712,6 +840,7 @@ "version": "2.4.1", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", "dependencies": { "ee-first": "1.1.1" }, @@ -731,14 +860,16 @@ "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", "engines": { "node": ">= 0.8" } }, "node_modules/path-to-regexp": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", - "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==" + "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" }, "node_modules/picomatch": { "version": "2.3.1", @@ -769,11 +900,12 @@ "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==" }, "node_modules/qs": { - "version": "6.11.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", - "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", + "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", + "license": "BSD-3-Clause", "dependencies": { - "side-channel": "^1.0.4" + "side-channel": "^1.0.6" }, "engines": { "node": ">=0.6" @@ -786,14 +918,16 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", "engines": { "node": ">= 0.6" } }, "node_modules/raw-body": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", - "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", + "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==", + "license": "MIT", "dependencies": { "bytes": "3.1.2", "http-errors": "2.0.0", @@ -837,7 +971,8 @@ "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" }, "node_modules/semver": { "version": "7.5.4", @@ -854,9 +989,10 @@ } }, "node_modules/send": { - "version": "0.18.0", - "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", - "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==", + "version": "0.19.0", + "resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz", + "integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==", + "license": "MIT", "dependencies": { "debug": "2.6.9", "depd": "2.0.0", @@ -876,20 +1012,31 @@ "node": ">= 0.8.0" } }, + "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", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/send/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==" + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" }, "node_modules/serve-static": { - "version": "1.15.0", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", - "integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==", + "version": "1.16.2", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.2.tgz", + "integrity": "sha512-VqpjJZKadQB/PEbEwvFdO43Ax5dFBZ2UECszz8bQ7pi7wt//PWe1P6MN7eCnjsatYtBT6EuiClbjSWP2WrIoTw==", + "license": "MIT", "dependencies": { - "encodeurl": "~1.0.2", + "encodeurl": "~2.0.0", "escape-html": "~1.0.3", "parseurl": "~1.3.3", - "send": "0.18.0" + "send": "0.19.0" }, "engines": { "node": ">= 0.8.0" @@ -898,16 +1045,76 @@ "node_modules/setprototypeof": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", - "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" }, "node_modules/side-channel": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", - "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", "dependencies": { - "call-bind": "^1.0.0", - "get-intrinsic": "^1.0.2", - "object-inspect": "^1.9.0" + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -928,6 +1135,7 @@ "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" } @@ -958,6 +1166,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", "engines": { "node": ">=0.6" } @@ -977,6 +1186,7 @@ "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", "dependencies": { "media-typer": "0.3.0", "mime-types": "~2.1.24" @@ -994,6 +1204,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", "engines": { "node": ">= 0.8" } diff --git a/server/package.json b/server/package.json index 7aa0847c..9bc8654d 100644 --- a/server/package.json +++ b/server/package.json @@ -19,8 +19,9 @@ "homepage": "https://github.com/ironhack-labs/cohort-tools-project#readme", "dependencies": { "cookie-parser": "^1.4.6", - "express": "^4.18.2", + "express": "^4.21.2", "morgan": "^1.10.0", "nodemon": "^3.0.1" - } + }, + "keywords": [] } From b12ab9f16368a575d1665e118c7662a7cbb6b14f Mon Sep 17 00:00:00 2001 From: Gabriele Capezzuto Date: Thu, 29 May 2025 19:02:40 +0200 Subject: [PATCH 02/14] fixed hopefully --- server/app.js | 5 +++-- server/package-lock.json | 23 +++++++++++++++++++++++ server/package.json | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/server/app.js b/server/app.js index 38d628ad..754a713c 100644 --- a/server/app.js +++ b/server/app.js @@ -8,8 +8,9 @@ const path = require("path"); const PORT = 5005; // STATIC DATA - Import JSON data -const students = require("./data/students.json"); -const cohorts = require("./data/cohorts.json"); +const students = require("./students.json"); +const cohorts = require("./cohorts.json"); + // INITIALIZE EXPRESS APP const app = express(); diff --git a/server/package-lock.json b/server/package-lock.json index 06fc345f..b4e86945 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "cookie-parser": "^1.4.6", + "cors": "^2.8.5", "express": "^4.21.2", "morgan": "^1.10.0", "nodemon": "^3.0.1" @@ -236,6 +237,19 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -824,6 +838,15 @@ "node": ">=0.10.0" } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-inspect": { "version": "1.13.4", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", diff --git a/server/package.json b/server/package.json index 9bc8654d..85878b65 100644 --- a/server/package.json +++ b/server/package.json @@ -19,6 +19,7 @@ "homepage": "https://github.com/ironhack-labs/cohort-tools-project#readme", "dependencies": { "cookie-parser": "^1.4.6", + "cors": "^2.8.5", "express": "^4.21.2", "morgan": "^1.10.0", "nodemon": "^3.0.1" From 2eb84fac3fac8757de645443fa8e3cad4580a339 Mon Sep 17 00:00:00 2001 From: Gabriele Capezzuto Date: Thu, 29 May 2025 20:05:55 +0200 Subject: [PATCH 03/14] mongoose --- client/index.html | 2 +- client/package-lock.json | 350 +++++++++++++++++++++++++++++++++++++-- client/package.json | 1 + server/app.js | 45 +++-- 4 files changed, 365 insertions(+), 33 deletions(-) diff --git a/client/index.html b/client/index.html index 2ef3a4d1..e81b0322 100644 --- a/client/index.html +++ b/client/index.html @@ -2,7 +2,7 @@ - + Cohort Tools diff --git a/client/package-lock.json b/client/package-lock.json index 03ddba3c..bfa854da 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -9,6 +9,7 @@ "version": "1.3.0", "dependencies": { "axios": "^1.4.0", + "mongoose": "^8.15.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.11.2" @@ -891,6 +892,15 @@ "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", "dev": true }, + "node_modules/@mongodb-js/saslprep": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.2.2.tgz", + "integrity": "sha512-EB0O3SCSNRUFk66iRCpI+cXzIjdswfCs7F6nOC3RAGJ7xr5YhaicvsRwJ9eyzYvYRlCSDUO/c7g4yNulxKC1WA==", + "license": "MIT", + "dependencies": { + "sparse-bitfield": "^3.0.3" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -966,6 +976,21 @@ "integrity": "sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==", "dev": true }, + "node_modules/@types/webidl-conversions": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", + "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==", + "license": "MIT" + }, + "node_modules/@types/whatwg-url": { + "version": "11.0.5", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.5.tgz", + "integrity": "sha512-coYR071JRaHa+xoEvvYqvnIHaVqaYrLPbsufM9BF63HkwI5Lgmy2QR8Q5K/lYDYo5AK82wOvSOS0UsLTpTG7uQ==", + "license": "MIT", + "dependencies": { + "@types/webidl-conversions": "*" + } + }, "node_modules/@vitejs/plugin-react": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-4.0.0.tgz", @@ -1261,6 +1286,15 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/bson": { + "version": "6.10.3", + "resolved": "https://registry.npmjs.org/bson/-/bson-6.10.3.tgz", + "integrity": "sha512-MTxGsqgYTwfshYWTRdmZRC+M7FnG1b4y7RO7p2k3X24Wq0yv1m77Wsj0BzlPzd/IowgESfsruQCUToa7vbOpPQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=16.20.1" + } + }, "node_modules/call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", @@ -1448,7 +1482,6 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", - "dev": true, "dependencies": { "ms": "2.1.2" }, @@ -2775,6 +2808,15 @@ "node": ">=4.0" } }, + "node_modules/kareem": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.6.3.tgz", + "integrity": "sha512-C3iHfuGUXK2u8/ipq9LfjFfXFxAZMQJJq7vLS45r3D9Y2xQ/m4S8zaR4zMLFWh9AsNPXmcFfUDhTEO8UIC/V6Q==", + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -2844,6 +2886,12 @@ "yallist": "^3.0.2" } }, + "node_modules/memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "license": "MIT" + }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -2897,11 +2945,115 @@ "node": "*" } }, + "node_modules/mongodb": { + "version": "6.16.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.16.0.tgz", + "integrity": "sha512-D1PNcdT0y4Grhou5Zi/qgipZOYeWrhLEpk33n3nm6LGtz61jvO88WlrWCK/bigMjpnOdAUKKQwsGIl0NtWMyYw==", + "license": "Apache-2.0", + "dependencies": { + "@mongodb-js/saslprep": "^1.1.9", + "bson": "^6.10.3", + "mongodb-connection-string-url": "^3.0.0" + }, + "engines": { + "node": ">=16.20.1" + }, + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.188.0", + "@mongodb-js/zstd": "^1.1.0 || ^2.0.0", + "gcp-metadata": "^5.2.0", + "kerberos": "^2.0.1", + "mongodb-client-encryption": ">=6.0.0 <7", + "snappy": "^7.2.2", + "socks": "^2.7.1" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "@mongodb-js/zstd": { + "optional": true + }, + "gcp-metadata": { + "optional": true + }, + "kerberos": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + }, + "socks": { + "optional": true + } + } + }, + "node_modules/mongodb-connection-string-url": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.2.tgz", + "integrity": "sha512-rMO7CGo/9BFwyZABcKAWL8UJwH/Kc2x0g72uhDWzG48URRax5TCIcJ7Rc3RZqffZzO/Gwff/jyKwCU9TN8gehA==", + "license": "Apache-2.0", + "dependencies": { + "@types/whatwg-url": "^11.0.2", + "whatwg-url": "^14.1.0 || ^13.0.0" + } + }, + "node_modules/mongoose": { + "version": "8.15.1", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.15.1.tgz", + "integrity": "sha512-RhQ4DzmBi5BNGcS0w4u1vdMRIKcteXTCNzDt1j7XRcdWYBz1MjMjulBhPaeC5jBCHOD1yinuOFTTSOWLLGexWw==", + "license": "MIT", + "dependencies": { + "bson": "^6.10.3", + "kareem": "2.6.3", + "mongodb": "~6.16.0", + "mpath": "0.9.0", + "mquery": "5.0.0", + "ms": "2.1.3", + "sift": "17.1.3" + }, + "engines": { + "node": ">=16.20.1" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mongoose" + } + }, + "node_modules/mongoose/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/mpath": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==", + "license": "MIT", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mquery": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz", + "integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==", + "license": "MIT", + "dependencies": { + "debug": "4.x" + }, + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "node_modules/mz": { "version": "2.7.0", @@ -3388,10 +3540,10 @@ "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" }, "node_modules/punycode": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", - "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", - "dev": true, + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "license": "MIT", "engines": { "node": ">=6" } @@ -3678,6 +3830,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sift": { + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", + "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==", + "license": "MIT" + }, "node_modules/source-map-js": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", @@ -3687,6 +3845,15 @@ "node": ">=0.10.0" } }, + "node_modules/sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "license": "MIT", + "dependencies": { + "memory-pager": "^1.0.2" + } + }, "node_modules/string.prototype.matchall": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/string.prototype.matchall/-/string.prototype.matchall-4.0.8.tgz", @@ -3943,6 +4110,18 @@ "node": ">=8.0" } }, + "node_modules/tr46": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz", + "integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==", + "license": "MIT", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/ts-interface-checker": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", @@ -4095,6 +4274,28 @@ } } }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-url": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", + "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "license": "MIT", + "dependencies": { + "tr46": "^5.1.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -4720,6 +4921,14 @@ } } }, + "@mongodb-js/saslprep": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.2.2.tgz", + "integrity": "sha512-EB0O3SCSNRUFk66iRCpI+cXzIjdswfCs7F6nOC3RAGJ7xr5YhaicvsRwJ9eyzYvYRlCSDUO/c7g4yNulxKC1WA==", + "requires": { + "sparse-bitfield": "^3.0.3" + } + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -4783,6 +4992,19 @@ "integrity": "sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==", "dev": true }, + "@types/webidl-conversions": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", + "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==" + }, + "@types/whatwg-url": { + "version": "11.0.5", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.5.tgz", + "integrity": "sha512-coYR071JRaHa+xoEvvYqvnIHaVqaYrLPbsufM9BF63HkwI5Lgmy2QR8Q5K/lYDYo5AK82wOvSOS0UsLTpTG7uQ==", + "requires": { + "@types/webidl-conversions": "*" + } + }, "@vitejs/plugin-react": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-4.0.0.tgz", @@ -4989,6 +5211,11 @@ "update-browserslist-db": "^1.0.10" } }, + "bson": { + "version": "6.10.3", + "resolved": "https://registry.npmjs.org/bson/-/bson-6.10.3.tgz", + "integrity": "sha512-MTxGsqgYTwfshYWTRdmZRC+M7FnG1b4y7RO7p2k3X24Wq0yv1m77Wsj0BzlPzd/IowgESfsruQCUToa7vbOpPQ==" + }, "call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", @@ -5123,7 +5350,6 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", - "dev": true, "requires": { "ms": "2.1.2" } @@ -6076,6 +6302,11 @@ "object.assign": "^4.1.3" } }, + "kareem": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.6.3.tgz", + "integrity": "sha512-C3iHfuGUXK2u8/ipq9LfjFfXFxAZMQJJq7vLS45r3D9Y2xQ/m4S8zaR4zMLFWh9AsNPXmcFfUDhTEO8UIC/V6Q==" + }, "levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -6130,6 +6361,11 @@ "yallist": "^3.0.2" } }, + "memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==" + }, "merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -6168,11 +6404,63 @@ "brace-expansion": "^1.1.7" } }, + "mongodb": { + "version": "6.16.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.16.0.tgz", + "integrity": "sha512-D1PNcdT0y4Grhou5Zi/qgipZOYeWrhLEpk33n3nm6LGtz61jvO88WlrWCK/bigMjpnOdAUKKQwsGIl0NtWMyYw==", + "requires": { + "@mongodb-js/saslprep": "^1.1.9", + "bson": "^6.10.3", + "mongodb-connection-string-url": "^3.0.0" + } + }, + "mongodb-connection-string-url": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.2.tgz", + "integrity": "sha512-rMO7CGo/9BFwyZABcKAWL8UJwH/Kc2x0g72uhDWzG48URRax5TCIcJ7Rc3RZqffZzO/Gwff/jyKwCU9TN8gehA==", + "requires": { + "@types/whatwg-url": "^11.0.2", + "whatwg-url": "^14.1.0 || ^13.0.0" + } + }, + "mongoose": { + "version": "8.15.1", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.15.1.tgz", + "integrity": "sha512-RhQ4DzmBi5BNGcS0w4u1vdMRIKcteXTCNzDt1j7XRcdWYBz1MjMjulBhPaeC5jBCHOD1yinuOFTTSOWLLGexWw==", + "requires": { + "bson": "^6.10.3", + "kareem": "2.6.3", + "mongodb": "~6.16.0", + "mpath": "0.9.0", + "mquery": "5.0.0", + "ms": "2.1.3", + "sift": "17.1.3" + }, + "dependencies": { + "ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + } + } + }, + "mpath": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==" + }, + "mquery": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz", + "integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==", + "requires": { + "debug": "4.x" + } + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "mz": { "version": "2.7.0", @@ -6494,10 +6782,9 @@ "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" }, "punycode": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", - "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", - "dev": true + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==" }, "queue-microtask": { "version": "1.2.3", @@ -6681,12 +6968,25 @@ "object-inspect": "^1.9.0" } }, + "sift": { + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", + "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==" + }, "source-map-js": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==", "dev": true }, + "sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "requires": { + "memory-pager": "^1.0.2" + } + }, "string.prototype.matchall": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/string.prototype.matchall/-/string.prototype.matchall-4.0.8.tgz", @@ -6879,6 +7179,14 @@ "is-number": "^7.0.0" } }, + "tr46": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz", + "integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==", + "requires": { + "punycode": "^2.3.1" + } + }, "ts-interface-checker": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", @@ -6960,6 +7268,20 @@ "rollup": "^3.21.0" } }, + "webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==" + }, + "whatwg-url": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", + "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "requires": { + "tr46": "^5.1.0", + "webidl-conversions": "^7.0.0" + } + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/client/package.json b/client/package.json index 6720efe9..1beba05c 100644 --- a/client/package.json +++ b/client/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "axios": "^1.4.0", + "mongoose": "^8.15.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.11.2" diff --git a/server/app.js b/server/app.js index 754a713c..b8873dd2 100644 --- a/server/app.js +++ b/server/app.js @@ -4,43 +4,52 @@ const morgan = require("morgan"); const cookieParser = require("cookie-parser"); const cors = require("cors"); const path = require("path"); +const mongoose = require("mongoose"); const PORT = 5005; -// STATIC DATA - Import JSON data +// STATIC DATA - (you'll eventually remove this once DB is fully integrated) const students = require("./students.json"); const cohorts = require("./cohorts.json"); - // INITIALIZE EXPRESS APP const app = express(); // MIDDLEWARE -app.use(cors()); // Enable CORS -app.use(express.json()); // Parse JSON payloads -app.use(morgan("dev")); // Log HTTP requests -app.use(express.static("public")); // Serve static assets -app.use(express.urlencoded({ extended: false })); // Parse URL-encoded bodies -app.use(cookieParser()); // Parse cookies +app.use(cors()); +app.use(express.json()); +app.use(morgan("dev")); +app.use(express.static("public")); +app.use(express.urlencoded({ extended: false })); +app.use(cookieParser()); // ROUTES - -// Route to serve the API documentation HTML file app.get("/docs", (req, res) => { res.sendFile(path.join(__dirname, "views", "docs.html")); }); -// Route to get all students app.get("/api/students", (req, res) => { - res.json(students); + res.json(students); // Later: replace with MongoDB find() }); -// Route to get all cohorts app.get("/api/cohorts", (req, res) => { - res.json(cohorts); + res.json(cohorts); // Later: replace with MongoDB find() }); -// START SERVER -app.listen(PORT, () => { - console.log(`✅ Server is running at http://localhost:${PORT}`); -}); +// MONGODB CONNECTION +const MONGODB_URI = "mongodb://localhost:27017/cohort-tools-api"; + +mongoose + .connect(MONGODB_URI) + .then(() => { + console.log("✅ Connected to MongoDB"); + + + app.listen(PORT, () => { + console.log(`✅ Server is running at http://localhost:${PORT}`); + }); + }) + .catch((err) => { + console.error("❌ Failed to connect to MongoDB:", err); + }); + From c67e9ce86ba8c76ff05c9b07f322393a60f7d325 Mon Sep 17 00:00:00 2001 From: Gabriele Capezzuto Date: Thu, 29 May 2025 20:39:00 +0200 Subject: [PATCH 04/14] cohort --- server/app.js | 1 + server/models/cohort.model.js | 50 ++++++++++++++++++++++++++++++++++ server/models/student.model.js | 0 3 files changed, 51 insertions(+) create mode 100644 server/models/cohort.model.js create mode 100644 server/models/student.model.js diff --git a/server/app.js b/server/app.js index b8873dd2..99b456e2 100644 --- a/server/app.js +++ b/server/app.js @@ -5,6 +5,7 @@ const cookieParser = require("cookie-parser"); const cors = require("cors"); const path = require("path"); const mongoose = require("mongoose"); +const Cohort = require("./server/models/cohort.model"); const PORT = 5005; diff --git a/server/models/cohort.model.js b/server/models/cohort.model.js new file mode 100644 index 00000000..f33d177e --- /dev/null +++ b/server/models/cohort.model.js @@ -0,0 +1,50 @@ +const { Schema, model } = require("mongoose"); + +const cohortSchema = new Schema({ + cohortSlug: { + type: String, + required: true, + unique: true, + }, + cohortName: { + type: String, + required: true, + }, + program: { + type: String, + enum: ["Web Dev", "UX/UI", "Data Analytics", "Cybersecurity"], + }, + format: { + type: String, + enum: ["Full Time", "Part Time"], + }, + campus: { + type: String, + enum: ["Madrid", "Barcelona", "Miami", "Paris", "Berlin", "Amsterdam", "Lisbon", "Remote"], + }, + startDate: { + type: Date, + default: Date.now, + }, + endDate: { + type: Date, + }, + inProgress: { + type: Boolean, + default: false, + }, + programManager: { + type: String, + required: true, + }, + leadTeacher: { + type: String, + required: true, + }, + totalHours: { + type: Number, + default: 360, + }, +}); + +module.exports = model("Cohort", cohortSchema); diff --git a/server/models/student.model.js b/server/models/student.model.js new file mode 100644 index 00000000..e69de29b From 32f353fb04773aafca305a01c14b09db144a02fd Mon Sep 17 00:00:00 2001 From: Victor Vikhal Date: Thu, 29 May 2025 20:39:08 +0200 Subject: [PATCH 05/14] modes-student schema done --- server/app.js | 12 ++ server/models/student.model.js | 59 +++++++++ server/package-lock.json | 235 +++++++++++++++++++++++++++++++++ server/package.json | 1 + 4 files changed, 307 insertions(+) create mode 100644 server/models/student.model.js diff --git a/server/app.js b/server/app.js index b8873dd2..7262430d 100644 --- a/server/app.js +++ b/server/app.js @@ -6,6 +6,8 @@ const cors = require("cors"); const path = require("path"); const mongoose = require("mongoose"); +const Student = require("./server/models/student"); + const PORT = 5005; // STATIC DATA - (you'll eventually remove this once DB is fully integrated) @@ -49,6 +51,16 @@ mongoose console.log(`✅ Server is running at http://localhost:${PORT}`); }); }) + + .then(() => { + return students.find() + }) + + .then((response) => { + console.log(response) + console.log("todo gucci") + }) + .catch((err) => { console.error("❌ Failed to connect to MongoDB:", err); }); diff --git a/server/models/student.model.js b/server/models/student.model.js new file mode 100644 index 00000000..dd0039f2 --- /dev/null +++ b/server/models/student.model.js @@ -0,0 +1,59 @@ +const mongoose = require("mongoose") + + +//creating schema +const studentSchema = new mongoose.Schema({ + + firstName: { + type: String, + required: true + }, + lastName: { + type: String, + required: true + }, + email: { + type: String, + required: true, + unique: true + }, + phone: { + type: String, + required: true + }, + linkedinUrl: { + type: String, + default: "" + }, + languages: { + type: [String], + enum: ["English", "Spanish", "German", "Portuguese", "Dutch", "Other"], + default: [] + }, + program: { + type: String, + enum: ["Web Dev", "UX/UI", "Data Analytics", "Cybersecurity"], + required: true + }, + background: { + type: String, + default: '', + }, + image: { + type: String, + default: 'https://i.imgur.com/r8bo8u7.png', + }, + cohort: { + type: mongoose.Schema.Types.ObjectId, + ref: 'Cohort', + }, + projects: { + type: [], + default: [], + }, + +}); + +//creating new model + +module.exports = mongoose.model("Student", studentSchema); \ No newline at end of file diff --git a/server/package-lock.json b/server/package-lock.json index b4e86945..cb466162 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -12,10 +12,35 @@ "cookie-parser": "^1.4.6", "cors": "^2.8.5", "express": "^4.21.2", + "mongoose": "^8.15.1", "morgan": "^1.10.0", "nodemon": "^3.0.1" } }, + "node_modules/@mongodb-js/saslprep": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.2.2.tgz", + "integrity": "sha512-EB0O3SCSNRUFk66iRCpI+cXzIjdswfCs7F6nOC3RAGJ7xr5YhaicvsRwJ9eyzYvYRlCSDUO/c7g4yNulxKC1WA==", + "license": "MIT", + "dependencies": { + "sparse-bitfield": "^3.0.3" + } + }, + "node_modules/@types/webidl-conversions": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", + "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==", + "license": "MIT" + }, + "node_modules/@types/whatwg-url": { + "version": "11.0.5", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.5.tgz", + "integrity": "sha512-coYR071JRaHa+xoEvvYqvnIHaVqaYrLPbsufM9BF63HkwI5Lgmy2QR8Q5K/lYDYo5AK82wOvSOS0UsLTpTG7uQ==", + "license": "MIT", + "dependencies": { + "@types/webidl-conversions": "*" + } + }, "node_modules/abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -123,6 +148,15 @@ "node": ">=8" } }, + "node_modules/bson": { + "version": "6.10.3", + "resolved": "https://registry.npmjs.org/bson/-/bson-6.10.3.tgz", + "integrity": "sha512-MTxGsqgYTwfshYWTRdmZRC+M7FnG1b4y7RO7p2k3X24Wq0yv1m77Wsj0BzlPzd/IowgESfsruQCUToa7vbOpPQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=16.20.1" + } + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -649,6 +683,15 @@ "node": ">=0.12.0" } }, + "node_modules/kareem": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.6.3.tgz", + "integrity": "sha512-C3iHfuGUXK2u8/ipq9LfjFfXFxAZMQJJq7vLS45r3D9Y2xQ/m4S8zaR4zMLFWh9AsNPXmcFfUDhTEO8UIC/V6Q==", + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -678,6 +721,12 @@ "node": ">= 0.6" } }, + "node_modules/memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "license": "MIT" + }, "node_modules/merge-descriptors": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", @@ -737,6 +786,90 @@ "node": "*" } }, + "node_modules/mongodb": { + "version": "6.16.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.16.0.tgz", + "integrity": "sha512-D1PNcdT0y4Grhou5Zi/qgipZOYeWrhLEpk33n3nm6LGtz61jvO88WlrWCK/bigMjpnOdAUKKQwsGIl0NtWMyYw==", + "license": "Apache-2.0", + "dependencies": { + "@mongodb-js/saslprep": "^1.1.9", + "bson": "^6.10.3", + "mongodb-connection-string-url": "^3.0.0" + }, + "engines": { + "node": ">=16.20.1" + }, + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.188.0", + "@mongodb-js/zstd": "^1.1.0 || ^2.0.0", + "gcp-metadata": "^5.2.0", + "kerberos": "^2.0.1", + "mongodb-client-encryption": ">=6.0.0 <7", + "snappy": "^7.2.2", + "socks": "^2.7.1" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "@mongodb-js/zstd": { + "optional": true + }, + "gcp-metadata": { + "optional": true + }, + "kerberos": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + }, + "socks": { + "optional": true + } + } + }, + "node_modules/mongodb-connection-string-url": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.2.tgz", + "integrity": "sha512-rMO7CGo/9BFwyZABcKAWL8UJwH/Kc2x0g72uhDWzG48URRax5TCIcJ7Rc3RZqffZzO/Gwff/jyKwCU9TN8gehA==", + "license": "Apache-2.0", + "dependencies": { + "@types/whatwg-url": "^11.0.2", + "whatwg-url": "^14.1.0 || ^13.0.0" + } + }, + "node_modules/mongoose": { + "version": "8.15.1", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.15.1.tgz", + "integrity": "sha512-RhQ4DzmBi5BNGcS0w4u1vdMRIKcteXTCNzDt1j7XRcdWYBz1MjMjulBhPaeC5jBCHOD1yinuOFTTSOWLLGexWw==", + "license": "MIT", + "dependencies": { + "bson": "^6.10.3", + "kareem": "2.6.3", + "mongodb": "~6.16.0", + "mpath": "0.9.0", + "mquery": "5.0.0", + "ms": "2.1.3", + "sift": "17.1.3" + }, + "engines": { + "node": ">=16.20.1" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mongoose" + } + }, + "node_modules/mongoose/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, "node_modules/morgan": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz", @@ -763,6 +896,50 @@ "node": ">= 0.8" } }, + "node_modules/mpath": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==", + "license": "MIT", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mquery": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz", + "integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==", + "license": "MIT", + "dependencies": { + "debug": "4.x" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/mquery/node_modules/debug": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz", + "integrity": "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/mquery/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, "node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -922,6 +1099,15 @@ "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", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/qs": { "version": "6.13.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", @@ -1143,6 +1329,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sift": { + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", + "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==", + "license": "MIT" + }, "node_modules/simple-update-notifier": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-2.0.0.tgz", @@ -1154,6 +1346,15 @@ "node": ">=10" } }, + "node_modules/sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "license": "MIT", + "dependencies": { + "memory-pager": "^1.0.2" + } + }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -1205,6 +1406,18 @@ "nodetouch": "bin/nodetouch.js" } }, + "node_modules/tr46": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz", + "integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==", + "license": "MIT", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", @@ -1248,6 +1461,28 @@ "node": ">= 0.8" } }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-url": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", + "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "license": "MIT", + "dependencies": { + "tr46": "^5.1.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", diff --git a/server/package.json b/server/package.json index 85878b65..a72cb72d 100644 --- a/server/package.json +++ b/server/package.json @@ -21,6 +21,7 @@ "cookie-parser": "^1.4.6", "cors": "^2.8.5", "express": "^4.21.2", + "mongoose": "^8.15.1", "morgan": "^1.10.0", "nodemon": "^3.0.1" }, From d5597851b33830558f999b960adc516eb61ff146 Mon Sep 17 00:00:00 2001 From: Gabriele Capezzuto Date: Sat, 31 May 2025 15:46:06 +0200 Subject: [PATCH 06/14] cohort done --- server/app.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/server/app.js b/server/app.js index 8b767e66..33c34c85 100644 --- a/server/app.js +++ b/server/app.js @@ -5,9 +5,9 @@ const cookieParser = require("cookie-parser"); const cors = require("cors"); const path = require("path"); const mongoose = require("mongoose"); -const Cohort = require("./server/models/cohort.model"); +const Cohort = require("./models/cohort.model"); -const Student = require("./server/models/student"); +const Students = require("./models/student.model"); const PORT = 5005; @@ -35,8 +35,57 @@ app.get("/api/students", (req, res) => { res.json(students); // Later: replace with MongoDB find() }); -app.get("/api/cohorts", (req, res) => { - res.json(cohorts); // Later: replace with MongoDB find() +app.get("/api/cohorts", async (req, res) => { + try { + const cohorts = await Cohort.find(); + res.status(200).json(cohorts); + } catch (error) { + res.status(500).json({ message: "Error retrieving cohorts", error }); + } +}); + +// GET one cohort by ID +app.get("/api/cohorts/:cohortId", async (req, res) => { + try { + const cohort = await Cohort.findById(req.params.cohortId); + res.status(200).json(cohort); + } catch (error) { + res.status(500).json({ message: "Error retrieving cohort", error }); + } +}); + +// POST a new cohort +app.post("/api/cohorts", async (req, res) => { + try { + const newCohort = await Cohort.create(req.body); + res.status(201).json(newCohort); + } catch (error) { + res.status(500).json({ message: "Error creating cohort", error }); + } +}); + +// PUT update a cohort by ID +app.put("/api/cohorts/:cohortId", async (req, res) => { + try { + const updatedCohort = await Cohort.findByIdAndUpdate( + req.params.cohortId, + req.body, + { new: true } + ); + res.status(200).json(updatedCohort); + } catch (error) { + res.status(500).json({ message: "Error updating cohort", error }); + } +}); + +// DELETE a cohort by ID +app.delete("/api/cohorts/:cohortId", async (req, res) => { + try { + await Cohort.findByIdAndDelete(req.params.cohortId); + res.sendStatus(204); // No Content + } catch (error) { + res.status(500).json({ message: "Error deleting cohort", error }); + } }); // MONGODB CONNECTION @@ -54,7 +103,7 @@ mongoose }) .then(() => { - return students.find() + return Students.find() }) .then((response) => { From 85b94c520988899af04a13b7834d44464837568b Mon Sep 17 00:00:00 2001 From: Victor Vikhal Date: Sat, 31 May 2025 16:40:50 +0200 Subject: [PATCH 07/14] routes for student --- server/app.js | 53 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/server/app.js b/server/app.js index 8b767e66..9a48c2b0 100644 --- a/server/app.js +++ b/server/app.js @@ -5,15 +5,14 @@ const cookieParser = require("cookie-parser"); const cors = require("cors"); const path = require("path"); const mongoose = require("mongoose"); -const Cohort = require("./server/models/cohort.model"); +const Cohort = require("./models/cohort.model.js"); -const Student = require("./server/models/student"); +const Students = require("./models/student.model.js"); const PORT = 5005; // STATIC DATA - (you'll eventually remove this once DB is fully integrated) -const students = require("./students.json"); -const cohorts = require("./cohorts.json"); + // INITIALIZE EXPRESS APP const app = express(); @@ -31,10 +30,52 @@ app.get("/docs", (req, res) => { res.sendFile(path.join(__dirname, "views", "docs.html")); }); +//calling all students app.get("/api/students", (req, res) => { - res.json(students); // Later: replace with MongoDB find() + + Students.find() + .then(response => { + res.json(response) + }) + .catch(error => res.status(500).json(error)) + // Later: replace with MongoDB find() }); +// calling students with specified cohort +app.get("/api/students/cohort/:cohortId", (req, res, next) =>{ + const {cohortId} = req.params +//encuentra los estudiantes que tengan como cohort al cohortId. + Students.find(({ cohort: cohortId })).populate('cohort') + .then(response =>{ + res.json(response) + }) + .catch(error => res.status(500).json(error)) +}) + + +// calling specified student +app.get("/api/students/:studentId", (req, res, next) =>{ + const {studentId} = req.params + Students.findById(studentId) + .then(response =>{ + res.json(response) + }) + .catch(error => res.status(500).json(error)) +}) + +//creating new student +app.post("/api/students", (req, res, next) =>{ + Students.create() +}) +//updating specified student +app.put("/api/students/:studentId", (req, res, next) =>{ + const {studentId} = req.params + const updatedStudent = req.body + Students.findByIdAndUpdate(studentId, updatedStudent, {new: true}) +}) + + + app.get("/api/cohorts", (req, res) => { res.json(cohorts); // Later: replace with MongoDB find() }); @@ -54,7 +95,7 @@ mongoose }) .then(() => { - return students.find() + return Students.find() }) .then((response) => { From 169d44a2d66922db5dae19e1a9ff6c1d9d2a1eb1 Mon Sep 17 00:00:00 2001 From: Gabriele Capezzuto Date: Tue, 3 Jun 2025 21:07:37 +0200 Subject: [PATCH 08/14] day 3 hopefulyl done --- server/app.js | 1 + server/routes/student.routes.js | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 server/routes/student.routes.js diff --git a/server/app.js b/server/app.js index 33c34c85..26ce0a34 100644 --- a/server/app.js +++ b/server/app.js @@ -6,6 +6,7 @@ const cors = require("cors"); const path = require("path"); const mongoose = require("mongoose"); const Cohort = require("./models/cohort.model"); +const studentRoutes = require("./routes/student.routes"); const Students = require("./models/student.model"); diff --git a/server/routes/student.routes.js b/server/routes/student.routes.js new file mode 100644 index 00000000..ff09292f --- /dev/null +++ b/server/routes/student.routes.js @@ -0,0 +1,35 @@ +const express = require("express"); +const router = express.Router(); +const Student = require("../models/student.model"); + +// GET all students with populated cohort +router.get("/", async (req, res) => { + try { + const students = await Student.find().populate("cohort"); + res.json(students); + } catch (err) { + res.status(500).json({ message: err.message }); + } +}); + +// GET tanti STUDENTI (plurale) by cohort ID, with cohort populated +router.get("/cohort/:cohortId", async (req, res) => { + try { + const students = await Student.find({ cohort: req.params.cohortId }).populate("cohort"); + res.json(students); + } catch (err) { + res.status(500).json({ message: err.message }); + } +}); +// GET one student (SIngolare) by ID con il cohort populate +router.get("/:studentId", async (req, res) => { + try { + const student = await Student.findById(req.params.studentId).populate("cohort"); + if (!student) return res.status(404).json({ message: "Student not found" }); + res.json(student); + } catch (err) { + res.status(500).json({ message: err.message }); + } +}); + +module.exports = router; \ No newline at end of file From a223350f15a76647d931ab5b2cab7b3db4e35602 Mon Sep 17 00:00:00 2001 From: Victor Vikhal Date: Tue, 3 Jun 2025 21:10:59 +0200 Subject: [PATCH 09/14] all students routes done --- server/app.js | 69 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/server/app.js b/server/app.js index 27d5f56e..4c700839 100644 --- a/server/app.js +++ b/server/app.js @@ -13,7 +13,6 @@ const PORT = 5005; // STATIC DATA - (you'll eventually remove this once DB is fully integrated) - // INITIALIZE EXPRESS APP const app = express(); @@ -30,7 +29,7 @@ app.get("/docs", (req, res) => { res.sendFile(path.join(__dirname, "views", "docs.html")); }); -//calling all students +//Finding all students app.get("/api/students", (req, res) => { Students.find() @@ -38,14 +37,14 @@ app.get("/api/students", (req, res) => { res.json(response) }) .catch(error => res.status(500).json(error)) - // Later: replace with MongoDB find() + }); -// calling students with specified cohort +//Finding students with specified cohort app.get("/api/students/cohort/:cohortId", (req, res, next) =>{ const {cohortId} = req.params -//encuentra los estudiantes que tengan como cohort al cohortId. - Students.find(({ cohort: cohortId })).populate('cohort') + //encuentra los estudiantes que tengan como cohort al cohortId. + Students.find(({ cohort: cohortId })) .then(response =>{ res.json(response) }) @@ -53,7 +52,7 @@ app.get("/api/students/cohort/:cohortId", (req, res, next) =>{ }) -// calling specified student +//Finding a student by his id. app.get("/api/students/:studentId", (req, res, next) =>{ const {studentId} = req.params Students.findById(studentId) @@ -65,15 +64,69 @@ app.get("/api/students/:studentId", (req, res, next) =>{ //creating new student app.post("/api/students", (req, res, next) =>{ - Students.create() + + const studentData = req.body; //data from studet passed through the form in the frontend + const cohortId = studentData.cohort;// accessing to the given id of the cohort + + Cohort.findById(cohortId) + .then((foundCohort) => { + if (!foundCohort) { + return res.status(404).json({ message: "Cohort not found" }); + } + + // Crear al estudiante + return Students.create(studentData); + }) + .then((createdStudent) => { + if (createdStudent) { + res.status(201).json(createdStudent); + } + }) + .catch((err) => { + console.error("Error creating student:", err); + res.status(500).json({ + message: "Internal server error", + error: err.message, + }); + }); + + }) + //updating specified student app.put("/api/students/:studentId", (req, res, next) =>{ const {studentId} = req.params const updatedStudent = req.body Students.findByIdAndUpdate(studentId, updatedStudent, {new: true}) + .then((updatedStudent)=> { + if(!updatedStudent){ + return res.status(404).json({message: "student not found"}) + } + res.json(updatedStudent) + }) + .catch((err) => { + console.error("Error updating student:", err); + res.status(500).json({ message: "Internal server error", error: err.message }); + }); }) +//Delete student by Id. + +app.delete("/api/students/:studentId", (req, res) => { + const { studentId } = req.params; + + Students.findByIdAndDelete(studentId) + .then((deletedStudent) => { + if (!deletedStudent) { + return res.status(404).json({ message: "Student not found" }); + } + res.json({ message: "Student deleted successfully" }); + }) + .catch((err) => { + console.error("Error deleting student:", err); + res.status(500).json({ message: "Internal server error", error: err.message }); + }); +}); app.get("/api/cohorts", async (req, res) => { From b96ccd844d5828a5e7fd9a8e17ff71921f778a48 Mon Sep 17 00:00:00 2001 From: Victor Vikhal Date: Tue, 3 Jun 2025 21:12:28 +0200 Subject: [PATCH 10/14] "all students routes done" From 2b0de41e06303a551e41c7e71e30de2779bd2b5f Mon Sep 17 00:00:00 2001 From: Gabriele Capezzuto Date: Thu, 5 Jun 2025 19:14:07 +0200 Subject: [PATCH 11/14] middleware errorhandler done --- server/app.js | 15 +++++++-------- server/middleware/errorHandler.js | 13 +++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 server/middleware/errorHandler.js diff --git a/server/app.js b/server/app.js index c5568d76..ed54c95b 100644 --- a/server/app.js +++ b/server/app.js @@ -7,8 +7,9 @@ const path = require("path"); const mongoose = require("mongoose"); const Cohort = require("./models/cohort.model"); const studentRoutes = require("./routes/student.routes"); - const Students = require("./models/student.model"); +const errorHandler = require("./middleware/errorHandler"); + const PORT = 5005; @@ -31,14 +32,10 @@ app.get("/docs", (req, res) => { }); //Finding all students -app.get("/api/students", (req, res) => { - +app.get("/api/students", (req, res, next) => { Students.find() - .then(response => { - res.json(response) - }) - .catch(error => res.status(500).json(error)) - + .then(response => res.json(response)) + .catch(next); }); //Finding students with specified cohort @@ -183,6 +180,8 @@ app.delete("/api/cohorts/:cohortId", async (req, res) => { } }); +//error handler thingy +app.use(errorHandler); // MONGODB CONNECTION const MONGODB_URI = "mongodb://localhost:27017/cohort-tools-api"; diff --git a/server/middleware/errorHandler.js b/server/middleware/errorHandler.js new file mode 100644 index 00000000..5c8f2d8e --- /dev/null +++ b/server/middleware/errorHandler.js @@ -0,0 +1,13 @@ +const errorHandler = (err, req, res, next) => { + console.error(err.stack); // just to check if it fucks up or not :) + + const statusCode = err.statusCode || 500; + const message = err.message || "Internal server error"; + + res.status(statusCode).json({ + success: false, + error: message, + }); +}; + +module.exports = errorHandler; From 77ba82e17c933fb714574fa86f035e8b69da8e20 Mon Sep 17 00:00:00 2001 From: Victor Vikhal Date: Thu, 5 Jun 2025 19:43:08 +0200 Subject: [PATCH 12/14] middleware for error handdling added --- server/app.js | 78 ++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/server/app.js b/server/app.js index ed54c95b..d889d763 100644 --- a/server/app.js +++ b/server/app.js @@ -43,10 +43,8 @@ app.get("/api/students/cohort/:cohortId", (req, res, next) =>{ const {cohortId} = req.params //encuentra los estudiantes que tengan como cohort al cohortId. Students.find(({ cohort: cohortId })) - .then(response =>{ - res.json(response) - }) - .catch(error => res.status(500).json(error)) + .then(response =>res.json(response)) + .catch(next) }) @@ -54,10 +52,8 @@ app.get("/api/students/cohort/:cohortId", (req, res, next) =>{ app.get("/api/students/:studentId", (req, res, next) =>{ const {studentId} = req.params Students.findById(studentId) - .then(response =>{ - res.json(response) - }) - .catch(error => res.status(500).json(error)) + .then(response => res.json(response)) + .catch(next) }) //creating new student @@ -69,7 +65,9 @@ app.post("/api/students", (req, res, next) =>{ Cohort.findById(cohortId) .then((foundCohort) => { if (!foundCohort) { - return res.status(404).json({ message: "Cohort not found" }); + const error = new Error("Cohort not found"); + error.statusCode = 404; + throw error; } // Crear al estudiante @@ -80,13 +78,7 @@ app.post("/api/students", (req, res, next) =>{ res.status(201).json(createdStudent); } }) - .catch((err) => { - console.error("Error creating student:", err); - res.status(500).json({ - message: "Internal server error", - error: err.message, - }); - }); + .catch(next); }) @@ -98,41 +90,41 @@ app.put("/api/students/:studentId", (req, res, next) =>{ Students.findByIdAndUpdate(studentId, updatedStudent, {new: true}) .then((updatedStudent)=> { if(!updatedStudent){ - return res.status(404).json({message: "student not found"}) + const error = new Error("Student not found"); + error.statusCode = 404; + throw error; } res.json(updatedStudent) }) - .catch((err) => { - console.error("Error updating student:", err); - res.status(500).json({ message: "Internal server error", error: err.message }); - }); + .catch(next); }) //Delete student by Id. -app.delete("/api/students/:studentId", (req, res) => { +app.delete("/api/students/:studentId", (req, res, next) => { const { studentId } = req.params; Students.findByIdAndDelete(studentId) .then((deletedStudent) => { if (!deletedStudent) { - return res.status(404).json({ message: "Student not found" }); + const error = new Error("Student not found"); + error.statusCode = 404; + throw error } res.json({ message: "Student deleted successfully" }); }) - .catch((err) => { - console.error("Error deleting student:", err); - res.status(500).json({ message: "Internal server error", error: err.message }); - }); + .catch(next) }); -app.get("/api/cohorts", async (req, res) => { +app.get("/api/cohorts", async (req, res, next) => { try { const cohorts = await Cohort.find(); res.status(200).json(cohorts); - } catch (error) { - res.status(500).json({ message: "Error retrieving cohorts", error }); + } catch (err) { + const error = new Error("Error retrieving cohorts"); + error.statusCode = 500; + next(error); } }); @@ -141,8 +133,10 @@ app.get("/api/cohorts/:cohortId", async (req, res) => { try { const cohort = await Cohort.findById(req.params.cohortId); res.status(200).json(cohort); - } catch (error) { - res.status(500).json({ message: "Error retrieving cohort", error }); + } catch (err) { + const error = new Error("Error retrieving cohort"); + error.statusCode = 500; + next(error); } }); @@ -151,8 +145,10 @@ app.post("/api/cohorts", async (req, res) => { try { const newCohort = await Cohort.create(req.body); res.status(201).json(newCohort); - } catch (error) { - res.status(500).json({ message: "Error creating cohort", error }); + } catch (err) { + const error = new Error("Error creating cohort"); + error.statusCode = 500; + next(error); } }); @@ -165,8 +161,10 @@ app.put("/api/cohorts/:cohortId", async (req, res) => { { new: true } ); res.status(200).json(updatedCohort); - } catch (error) { - res.status(500).json({ message: "Error updating cohort", error }); + } catch (err) { + const error = new Error("Error updating cohort"); + error.statusCode = 500; + next(error); } }); @@ -175,13 +173,17 @@ app.delete("/api/cohorts/:cohortId", async (req, res) => { try { await Cohort.findByIdAndDelete(req.params.cohortId); res.sendStatus(204); // No Content - } catch (error) { - res.status(500).json({ message: "Error deleting cohort", error }); + } catch (err) { + const error = new Error("Error deleting cohort"); + error.statusCode = 500; + next(error); } }); //error handler thingy app.use(errorHandler); + + // MONGODB CONNECTION const MONGODB_URI = "mongodb://localhost:27017/cohort-tools-api"; From 98c8c28a169460a6d9a534a1309f483eb4ff12b5 Mon Sep 17 00:00:00 2001 From: Gabriele Capezzuto Date: Sat, 7 Jun 2025 14:39:18 +0200 Subject: [PATCH 13/14] new routes --- server/app.js | 7 ++++++ server/middleware/auth.js | 22 ++++++++++++++++ server/models/user.model.js | 11 ++++++++ server/routes/auth.routes.js | 49 ++++++++++++++++++++++++++++++++++++ server/routes/user.routes.js | 18 +++++++++++++ 5 files changed, 107 insertions(+) create mode 100644 server/middleware/auth.js create mode 100644 server/models/user.model.js create mode 100644 server/routes/auth.routes.js create mode 100644 server/routes/user.routes.js diff --git a/server/app.js b/server/app.js index d889d763..1c1c26a8 100644 --- a/server/app.js +++ b/server/app.js @@ -9,6 +9,9 @@ const Cohort = require("./models/cohort.model"); const studentRoutes = require("./routes/student.routes"); const Students = require("./models/student.model"); const errorHandler = require("./middleware/errorHandler"); +const authRoutes = require("./routes/auth.routes"); +const userRoutes = require("./routes/user.routes"); + const PORT = 5005; @@ -179,6 +182,10 @@ app.delete("/api/cohorts/:cohortId", async (req, res) => { next(error); } }); +// AUTHENTICATION ROUTES +app.use("/auth", authRoutes); +app.use("/api/users", userRoutes); + //error handler thingy app.use(errorHandler); diff --git a/server/middleware/auth.js b/server/middleware/auth.js new file mode 100644 index 00000000..f2429db8 --- /dev/null +++ b/server/middleware/auth.js @@ -0,0 +1,22 @@ +const jwt = require("jsonwebtoken"); +const expressJwt = require("express-jwt"); + +const secret = process.env.JWT_SECRET || "supersecret_jwt_key"; // use env variable in prod + +// Middleware to protect routes and decode token +const authenticate = expressJwt({ + secret, + algorithms: ["HS256"], + requestProperty: "auth", // decoded token will be in req.auth +}); + +// Function to sign a JWT token for a user +function signToken(user) { + return jwt.sign( + { id: user._id, email: user.email }, + secret, + { expiresIn: "1d" } + ); +} + +module.exports = { authenticate, signToken }; diff --git a/server/models/user.model.js b/server/models/user.model.js new file mode 100644 index 00000000..231d6f52 --- /dev/null +++ b/server/models/user.model.js @@ -0,0 +1,11 @@ +const mongoose = require("mongoose"); + +const userSchema = new mongoose.Schema({ + email: { type: String, unique: true, required: true }, + password: { type: String, required: true }, + name: { type: String, required: true } +}); + +const User = mongoose.model("User", userSchema); + +module.exports = User; diff --git a/server/routes/auth.routes.js b/server/routes/auth.routes.js new file mode 100644 index 00000000..d6aab9ec --- /dev/null +++ b/server/routes/auth.routes.js @@ -0,0 +1,49 @@ +const express = require("express"); +const bcrypt = require("bcryptjs"); +const User = require("../models/user.model"); +const { signToken, authenticate } = require("../middleware/auth"); + +const router = express.Router(); + +// Signup route +router.post("/signup", async (req, res, next) => { + try { + const { email, password, name } = req.body; + + // Check if user already exists + const existingUser = await User.findOne({ email }); + if (existingUser) return res.status(409).json({ message: "Email already in use" }); + + const hashedPassword = await bcrypt.hash(password, 10); + const newUser = await User.create({ email, password: hashedPassword, name }); + + res.status(201).json({ id: newUser._id, email: newUser.email, name: newUser.name }); + } catch (err) { + next(err); + } +}); + +// Login route +router.post("/login", async (req, res, next) => { + try { + const { email, password } = req.body; + + const user = await User.findOne({ email }); + if (!user) return res.status(401).json({ message: "Invalid email or password" }); + + const valid = await bcrypt.compare(password, user.password); + if (!valid) return res.status(401).json({ message: "Invalid email or password" }); + + const token = signToken(user); + res.json({ token }); + } catch (err) { + next(err); + } +}); + +// Token verify route - protected route example +router.get("/verify", authenticate, (req, res) => { + res.json({ message: "Token valid", user: req.auth }); +}); + +module.exports = router; diff --git a/server/routes/user.routes.js b/server/routes/user.routes.js new file mode 100644 index 00000000..1e26036d --- /dev/null +++ b/server/routes/user.routes.js @@ -0,0 +1,18 @@ +const express = require("express"); +const User = require("../models/user.model"); +const { authenticate } = require("../middleware/auth"); + +const router = express.Router(); + +// Get user by id - protected route +router.get("/:id", authenticate, async (req, res, next) => { + try { + const user = await User.findById(req.params.id).select("-password"); + if (!user) return res.status(404).json({ message: "User not found" }); + res.json(user); + } catch (err) { + next(err); + } +}); + +module.exports = router; From 3cd977db4d3d60c14bfcd012eb8efc89eb93bf88 Mon Sep 17 00:00:00 2001 From: Gabriele Capezzuto Date: Sat, 7 Jun 2025 15:07:20 +0200 Subject: [PATCH 14/14] committ --- server/app.js | 1 + server/middleware/auth.js | 26 ++++++++++++++------------ server/routes/auth.routes.js | 5 +++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/server/app.js b/server/app.js index 1c1c26a8..cc1e6688 100644 --- a/server/app.js +++ b/server/app.js @@ -11,6 +11,7 @@ const Students = require("./models/student.model"); const errorHandler = require("./middleware/errorHandler"); const authRoutes = require("./routes/auth.routes"); const userRoutes = require("./routes/user.routes"); +const User = require("./models/user.model"); diff --git a/server/middleware/auth.js b/server/middleware/auth.js index f2429db8..671fe9b4 100644 --- a/server/middleware/auth.js +++ b/server/middleware/auth.js @@ -1,22 +1,24 @@ const jwt = require("jsonwebtoken"); -const expressJwt = require("express-jwt"); - -const secret = process.env.JWT_SECRET || "supersecret_jwt_key"; // use env variable in prod - -// Middleware to protect routes and decode token +const { expressjwt: expressJwt } = require("express-jwt"); // :white_check_mark: CORREGIDO +const secret = process.env.JWT_SECRET || "supersecret_jwt_key"; // usa variable de entorno en producción +// Middleware para proteger rutas y decodificar el token const authenticate = expressJwt({ secret, algorithms: ["HS256"], - requestProperty: "auth", // decoded token will be in req.auth + requestProperty: "auth", // El usuario estará disponible en req.auth }); - -// Function to sign a JWT token for a user +// Función para firmar (crear) un token JWT para un usuario function signToken(user) { return jwt.sign( - { id: user._id, email: user.email }, - secret, - { expiresIn: "1d" } + { id: user._id, email: user.email }, // payload del token + secret, // clave secreta para firmarlo + { expiresIn: "1d" } // duración del token: 1 día ); } - module.exports = { authenticate, signToken }; + + + + + + diff --git a/server/routes/auth.routes.js b/server/routes/auth.routes.js index d6aab9ec..ec0fac2f 100644 --- a/server/routes/auth.routes.js +++ b/server/routes/auth.routes.js @@ -18,7 +18,8 @@ router.post("/signup", async (req, res, next) => { const newUser = await User.create({ email, password: hashedPassword, name }); res.status(201).json({ id: newUser._id, email: newUser.email, name: newUser.name }); - } catch (err) { + console.log("ajuhsdas");} + catch (err) { next(err); } }); @@ -41,7 +42,7 @@ router.post("/login", async (req, res, next) => { } }); -// Token verify route - protected route example +// Middleware to check if user is authenticated router.get("/verify", authenticate, (req, res) => { res.json({ message: "Token valid", user: req.auth }); });