From df070f2f37e6e8aae544298091f3c2ec21151cb6 Mon Sep 17 00:00:00 2001 From: Ingeborg Brommeland Austeid Date: Tue, 29 Oct 2024 14:43:11 +0100 Subject: [PATCH 01/11] adds content validation for creating posts --- docs/openapi.yml | 6 +++--- src/middleware/post.js | 22 ++++++++++++++++++++++ src/routes/post.js | 3 ++- 3 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 src/middleware/post.js diff --git a/docs/openapi.yml b/docs/openapi.yml index 9a064a1d..3fef1b5f 100644 --- a/docs/openapi.yml +++ b/docs/openapi.yml @@ -2,10 +2,10 @@ openapi: 3.0.3 info: title: Team Dev Server API description: |- - version: "1.0" + version: '1.0' servers: - - url: "http://localhost:4000/" + - url: 'http://localhost:4000/' tags: - name: user - name: post @@ -729,7 +729,7 @@ components: format: date-time profileImage: type: string - + Error: type: object properties: diff --git a/src/middleware/post.js b/src/middleware/post.js new file mode 100644 index 00000000..b3f7315d --- /dev/null +++ b/src/middleware/post.js @@ -0,0 +1,22 @@ +import { sendDataResponse } from '../utils/responses.js' + +export async function validatePostContent(req, res, next) { + const validateContent = (content) => { + const maxLength = 200 // Set maximum length + + if (!content || content.trim() === '') { + return 'Content cannot be empty or null' + } + if (content.length > maxLength) { + return `Content cannot exceed ${maxLength} characters` + } + return null + } + + const contentError = validateContent(req.body.content) + if (contentError) { + return sendDataResponse(res, 400, { content: contentError }) + } + + next() +} diff --git a/src/routes/post.js b/src/routes/post.js index 38f2b81b..b3a03a3e 100644 --- a/src/routes/post.js +++ b/src/routes/post.js @@ -7,10 +7,11 @@ import { deleteById } from '../controllers/post.js' import { validateAuthentication } from '../middleware/auth.js' +import { validatePostContent } from '../middleware/post.js' const router = Router() -router.post('/', validateAuthentication, create) +router.post('/', validateAuthentication, validatePostContent, create) router.get('/', validateAuthentication, getAll) router.get('/:id', validateAuthentication, getById) router.patch('/:id', validateAuthentication, updateById) From f9c842fefd9b76cc3a81e91a55490dcdf6a28acc Mon Sep 17 00:00:00 2001 From: eyvmal Date: Wed, 30 Oct 2024 15:50:45 +0100 Subject: [PATCH 02/11] simplified function --- src/middleware/post.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/middleware/post.js b/src/middleware/post.js index b3f7315d..e49ce287 100644 --- a/src/middleware/post.js +++ b/src/middleware/post.js @@ -1,21 +1,19 @@ import { sendDataResponse } from '../utils/responses.js' export async function validatePostContent(req, res, next) { - const validateContent = (content) => { - const maxLength = 200 // Set maximum length + const { content } = req.body + const maxLength = 200 - if (!content || content.trim() === '') { - return 'Content cannot be empty or null' - } - if (content.length > maxLength) { - return `Content cannot exceed ${maxLength} characters` - } - return null + if (!content || content.trim() === '') { + return sendDataResponse(res, 400, { + content: 'Content cannot be empty or null' + }) } - const contentError = validateContent(req.body.content) - if (contentError) { - return sendDataResponse(res, 400, { content: contentError }) + if (content.length > maxLength) { + return sendDataResponse(res, 400, { + content: `Content cannot exceed ${maxLength} characters` + }) } next() From de7fafe5a3260ecaa693edca0d25174abd835874 Mon Sep 17 00:00:00 2001 From: TMajlu Date: Thu, 31 Oct 2024 09:57:55 +0100 Subject: [PATCH 03/11] Tested post validation --- package-lock.json | 205 ++++++++++++++++++++++++++++++---------------- package.json | 4 +- 2 files changed, 138 insertions(+), 71 deletions(-) diff --git a/package-lock.json b/package-lock.json index 044145e5..5792fc24 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@prisma/client": "^3.12.0", + "@prisma/client": "^5.21.1", "bcrypt": "^5.0.1", "cors": "^2.8.5", "dotenv": "^16.0.0", @@ -27,10 +27,9 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^4.0.0", "eslint-plugin-promise": "^5.1.0", - "husky": "^7.0.4", "nodemon": "^2.0.15", "prettier": "^2.6.2", - "prisma": "^3.12.0" + "prisma": "^5.21.1" } }, "node_modules/@babel/code-frame": { @@ -202,15 +201,13 @@ } }, "node_modules/@prisma/client": { - "version": "3.15.2", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-3.15.2.tgz", - "integrity": "sha512-ErqtwhX12ubPhU4d++30uFY/rPcyvjk+mdifaZO5SeM21zS3t4jQrscy8+6IyB0GIYshl5ldTq6JSBo1d63i8w==", + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.21.1.tgz", + "integrity": "sha512-3n+GgbAZYjaS/k0M03yQsQfR1APbr411r74foknnsGpmhNKBG49VuUkxIU6jORgvJPChoD4WC4PqoHImN1FP0w==", "hasInstallScript": true, - "dependencies": { - "@prisma/engines-version": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" - }, + "license": "Apache-2.0", "engines": { - "node": ">=12.6" + "node": ">=16.13" }, "peerDependencies": { "prisma": "*" @@ -221,17 +218,62 @@ } } }, + "node_modules/@prisma/debug": { + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.21.1.tgz", + "integrity": "sha512-uY8SAhcnORhvgtOrNdvWS98Aq/nkQ9QDUxrWAgW8XrCZaI3j2X7zb7Xe6GQSh6xSesKffFbFlkw0c2luHQviZA==", + "devOptional": true, + "license": "Apache-2.0" + }, "node_modules/@prisma/engines": { - "version": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e", - "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz", - "integrity": "sha512-NHlojO1DFTsSi3FtEleL9QWXeSF/UjhCW0fgpi7bumnNZ4wj/eQ+BJJ5n2pgoOliTOGv9nX2qXvmHap7rJMNmg==", + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.21.1.tgz", + "integrity": "sha512-hGVTldUkIkTwoV8//hmnAAiAchi4oMEKD3aW5H2RrnI50tTdwza7VQbTTAyN3OIHWlK5DVg6xV7X8N/9dtOydA==", + "devOptional": true, + "hasInstallScript": true, + "license": "Apache-2.0", + "dependencies": { + "@prisma/debug": "5.21.1", + "@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", + "@prisma/fetch-engine": "5.21.1", + "@prisma/get-platform": "5.21.1" + } + }, + "node_modules/@prisma/engines/node_modules/@prisma/engines-version": { + "version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36.tgz", + "integrity": "sha512-qvnEflL0//lh44S/T9NcvTMxfyowNeUxTunPcDfKPjyJNrCNf2F1zQLcUv5UHAruECpX+zz21CzsC7V2xAeM7Q==", + "devOptional": true, + "license": "Apache-2.0" + }, + "node_modules/@prisma/fetch-engine": { + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.21.1.tgz", + "integrity": "sha512-70S31vgpCGcp9J+mh/wHtLCkVezLUqe/fGWk3J3JWZIN7prdYSlr1C0niaWUyNK2VflLXYi8kMjAmSxUVq6WGQ==", + "devOptional": true, + "license": "Apache-2.0", + "dependencies": { + "@prisma/debug": "5.21.1", + "@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", + "@prisma/get-platform": "5.21.1" + } + }, + "node_modules/@prisma/fetch-engine/node_modules/@prisma/engines-version": { + "version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36.tgz", + "integrity": "sha512-qvnEflL0//lh44S/T9NcvTMxfyowNeUxTunPcDfKPjyJNrCNf2F1zQLcUv5UHAruECpX+zz21CzsC7V2xAeM7Q==", "devOptional": true, - "hasInstallScript": true + "license": "Apache-2.0" }, - "node_modules/@prisma/engines-version": { - "version": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz", - "integrity": "sha512-e3k2Vd606efd1ZYy2NQKkT4C/pn31nehyLhVug6To/q8JT8FpiMrDy7zmm3KLF0L98NOQQcutaVtAPhzKhzn9w==" + "node_modules/@prisma/get-platform": { + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.21.1.tgz", + "integrity": "sha512-sRxjL3Igst3ct+e8ya/x//cDXmpLbZQ5vfps2N4tWl4VGKQAmym77C/IG/psSMsQKszc8uFC/q1dgmKFLUgXZQ==", + "devOptional": true, + "license": "Apache-2.0", + "dependencies": { + "@prisma/debug": "5.21.1" + } }, "node_modules/@types/json5": { "version": "0.0.29", @@ -1521,11 +1563,12 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "dev": true, "hasInstallScript": true, + "license": "MIT", "optional": true, "os": [ "darwin" @@ -1765,21 +1808,6 @@ "node": ">= 6" } }, - "node_modules/husky": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/husky/-/husky-7.0.4.tgz", - "integrity": "sha512-vbaCKN2QLtP/vD4yvs6iz6hBEo6wkSzs8HpRah1Z6aGmF2KW5PdYuAd7uX5a+OyBZHBhd+TFLqgjUgytQr4RvQ==", - "dev": true, - "bin": { - "husky": "lib/bin.js" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/typicode" - } - }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -2765,20 +2793,23 @@ } }, "node_modules/prisma": { - "version": "3.15.2", - "resolved": "https://registry.npmjs.org/prisma/-/prisma-3.15.2.tgz", - "integrity": "sha512-nMNSMZvtwrvoEQ/mui8L/aiCLZRCj5t6L3yujKpcDhIPk7garp8tL4nMx2+oYsN0FWBacevJhazfXAbV1kfBzA==", + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.21.1.tgz", + "integrity": "sha512-PB+Iqzld/uQBPaaw2UVIk84kb0ITsLajzsxzsadxxl54eaU5Gyl2/L02ysivHxK89t7YrfQJm+Ggk37uvM70oQ==", "devOptional": true, "hasInstallScript": true, + "license": "Apache-2.0", "dependencies": { - "@prisma/engines": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" + "@prisma/engines": "5.21.1" }, "bin": { - "prisma": "build/index.js", - "prisma2": "build/index.js" + "prisma": "build/index.js" }, "engines": { - "node": ">=12.6" + "node": ">=16.13" + }, + "optionalDependencies": { + "fsevents": "2.3.3" } }, "node_modules/progress": { @@ -3722,23 +3753,64 @@ } }, "@prisma/client": { - "version": "3.15.2", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-3.15.2.tgz", - "integrity": "sha512-ErqtwhX12ubPhU4d++30uFY/rPcyvjk+mdifaZO5SeM21zS3t4jQrscy8+6IyB0GIYshl5ldTq6JSBo1d63i8w==", + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.21.1.tgz", + "integrity": "sha512-3n+GgbAZYjaS/k0M03yQsQfR1APbr411r74foknnsGpmhNKBG49VuUkxIU6jORgvJPChoD4WC4PqoHImN1FP0w==", + "requires": {} + }, + "@prisma/debug": { + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.21.1.tgz", + "integrity": "sha512-uY8SAhcnORhvgtOrNdvWS98Aq/nkQ9QDUxrWAgW8XrCZaI3j2X7zb7Xe6GQSh6xSesKffFbFlkw0c2luHQviZA==", + "devOptional": true + }, + "@prisma/engines": { + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.21.1.tgz", + "integrity": "sha512-hGVTldUkIkTwoV8//hmnAAiAchi4oMEKD3aW5H2RrnI50tTdwza7VQbTTAyN3OIHWlK5DVg6xV7X8N/9dtOydA==", + "devOptional": true, "requires": { - "@prisma/engines-version": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" + "@prisma/debug": "5.21.1", + "@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", + "@prisma/fetch-engine": "5.21.1", + "@prisma/get-platform": "5.21.1" + }, + "dependencies": { + "@prisma/engines-version": { + "version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36.tgz", + "integrity": "sha512-qvnEflL0//lh44S/T9NcvTMxfyowNeUxTunPcDfKPjyJNrCNf2F1zQLcUv5UHAruECpX+zz21CzsC7V2xAeM7Q==", + "devOptional": true + } } }, - "@prisma/engines": { - "version": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e", - "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz", - "integrity": "sha512-NHlojO1DFTsSi3FtEleL9QWXeSF/UjhCW0fgpi7bumnNZ4wj/eQ+BJJ5n2pgoOliTOGv9nX2qXvmHap7rJMNmg==", - "devOptional": true + "@prisma/fetch-engine": { + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.21.1.tgz", + "integrity": "sha512-70S31vgpCGcp9J+mh/wHtLCkVezLUqe/fGWk3J3JWZIN7prdYSlr1C0niaWUyNK2VflLXYi8kMjAmSxUVq6WGQ==", + "devOptional": true, + "requires": { + "@prisma/debug": "5.21.1", + "@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", + "@prisma/get-platform": "5.21.1" + }, + "dependencies": { + "@prisma/engines-version": { + "version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36.tgz", + "integrity": "sha512-qvnEflL0//lh44S/T9NcvTMxfyowNeUxTunPcDfKPjyJNrCNf2F1zQLcUv5UHAruECpX+zz21CzsC7V2xAeM7Q==", + "devOptional": true + } + } }, - "@prisma/engines-version": { - "version": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz", - "integrity": "sha512-e3k2Vd606efd1ZYy2NQKkT4C/pn31nehyLhVug6To/q8JT8FpiMrDy7zmm3KLF0L98NOQQcutaVtAPhzKhzn9w==" + "@prisma/get-platform": { + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.21.1.tgz", + "integrity": "sha512-sRxjL3Igst3ct+e8ya/x//cDXmpLbZQ5vfps2N4tWl4VGKQAmym77C/IG/psSMsQKszc8uFC/q1dgmKFLUgXZQ==", + "devOptional": true, + "requires": { + "@prisma/debug": "5.21.1" + } }, "@types/json5": { "version": "0.0.29", @@ -4722,9 +4794,9 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "dev": true, "optional": true }, @@ -4893,12 +4965,6 @@ "debug": "4" } }, - "husky": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/husky/-/husky-7.0.4.tgz", - "integrity": "sha512-vbaCKN2QLtP/vD4yvs6iz6hBEo6wkSzs8HpRah1Z6aGmF2KW5PdYuAd7uX5a+OyBZHBhd+TFLqgjUgytQr4RvQ==", - "dev": true - }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -5616,12 +5682,13 @@ } }, "prisma": { - "version": "3.15.2", - "resolved": "https://registry.npmjs.org/prisma/-/prisma-3.15.2.tgz", - "integrity": "sha512-nMNSMZvtwrvoEQ/mui8L/aiCLZRCj5t6L3yujKpcDhIPk7garp8tL4nMx2+oYsN0FWBacevJhazfXAbV1kfBzA==", + "version": "5.21.1", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.21.1.tgz", + "integrity": "sha512-PB+Iqzld/uQBPaaw2UVIk84kb0ITsLajzsxzsadxxl54eaU5Gyl2/L02ysivHxK89t7YrfQJm+Ggk37uvM70oQ==", "devOptional": true, "requires": { - "@prisma/engines": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" + "@prisma/engines": "5.21.1", + "fsevents": "2.3.3" } }, "progress": { diff --git a/package.json b/package.json index 3021b44f..000af406 100644 --- a/package.json +++ b/package.json @@ -37,10 +37,10 @@ "eslint-plugin-promise": "^5.1.0", "nodemon": "^2.0.15", "prettier": "^2.6.2", - "prisma": "^3.12.0" + "prisma": "^5.21.1" }, "dependencies": { - "@prisma/client": "^3.12.0", + "@prisma/client": "^5.21.1", "bcrypt": "^5.0.1", "cors": "^2.8.5", "dotenv": "^16.0.0", From 2c6590454738bcca703d0d3d5272b297c438ca64 Mon Sep 17 00:00:00 2001 From: TMajlu Date: Thu, 31 Oct 2024 10:38:55 +0100 Subject: [PATCH 04/11] removed the second import --- src/middleware/post.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/middleware/post.js b/src/middleware/post.js index 7e62a5ee..f2d189c6 100644 --- a/src/middleware/post.js +++ b/src/middleware/post.js @@ -20,7 +20,6 @@ export async function validatePostOwnership(req, res, next) { return sendDataResponse(res, 500, { content: 'Internal server error' }) } } -import { sendDataResponse } from '../utils/responses.js' export async function validatePostContent(req, res, next) { const { content } = req.body From db0a06ef63ff87f46ceefff8f5b94beb8fcc8fa4 Mon Sep 17 00:00:00 2001 From: thomamn <126023720+thomamn@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:18:21 +0100 Subject: [PATCH 05/11] Changed the configurations. --- docs/openapi.yml | 6 +++--- src/routes/post.js | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/openapi.yml b/docs/openapi.yml index 3fef1b5f..9a064a1d 100644 --- a/docs/openapi.yml +++ b/docs/openapi.yml @@ -2,10 +2,10 @@ openapi: 3.0.3 info: title: Team Dev Server API description: |- - version: '1.0' + version: "1.0" servers: - - url: 'http://localhost:4000/' + - url: "http://localhost:4000/" tags: - name: user - name: post @@ -729,7 +729,7 @@ components: format: date-time profileImage: type: string - + Error: type: object properties: diff --git a/src/routes/post.js b/src/routes/post.js index 90e42261..1a337e46 100644 --- a/src/routes/post.js +++ b/src/routes/post.js @@ -7,6 +7,7 @@ import { deleteById } from '../controllers/post.js' import { validateAuthentication } from '../middleware/auth.js' + import { validatePostOwnership, validatePostContent From a83eb19d070e9e69f29bd355f86eb8ac0f100336 Mon Sep 17 00:00:00 2001 From: thomamn <126023720+thomamn@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:18:37 +0100 Subject: [PATCH 06/11] Changed these as well --- docs/openapi.yml | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/openapi.yml b/docs/openapi.yml index 9a064a1d..20c12b58 100644 --- a/docs/openapi.yml +++ b/docs/openapi.yml @@ -729,7 +729,7 @@ components: format: date-time profileImage: type: string - + Error: type: object properties: diff --git a/package.json b/package.json index 000af406..3021b44f 100644 --- a/package.json +++ b/package.json @@ -37,10 +37,10 @@ "eslint-plugin-promise": "^5.1.0", "nodemon": "^2.0.15", "prettier": "^2.6.2", - "prisma": "^5.21.1" + "prisma": "^3.12.0" }, "dependencies": { - "@prisma/client": "^5.21.1", + "@prisma/client": "^3.12.0", "bcrypt": "^5.0.1", "cors": "^2.8.5", "dotenv": "^16.0.0", From 68a53ee190a69b36500c3932409ab03fee587bee Mon Sep 17 00:00:00 2001 From: thomamn <126023720+thomamn@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:21:22 +0100 Subject: [PATCH 07/11] finish hopefully --- docs/openapi.yml | 94 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 4 deletions(-) diff --git a/docs/openapi.yml b/docs/openapi.yml index 20c12b58..7b6d1ed2 100644 --- a/docs/openapi.yml +++ b/docs/openapi.yml @@ -2,10 +2,10 @@ openapi: 3.0.3 info: title: Team Dev Server API description: |- - version: "1.0" + version: '1.0' servers: - - url: "http://localhost:4000/" + - url: 'http://localhost:4000/' tags: - name: user - name: post @@ -168,7 +168,7 @@ paths: schema: $ref: '#/components/schemas/Error' '400': - description: Invalid email/password supplied + description: Invalid email/password/profile information supplied content: application/json: schema: @@ -433,6 +433,86 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' + get: + tags: + - cohort + summary: Get all cohorts + operationId: getAllCohorts + security: + - bearerAuth: [] + responses: + '201': + description: success + content: + application/json: + schema: + type: object + properties: + status: + type: string + data: + properties: + cohort: + $ref: '#/components/schemas/Cohort' + '401': + description: fail + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + '500': + description: Server error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + /cohorts/{id}: + get: + tags: + - cohort + summary: Get a cohort by id + operationId: getCohortById + security: + - bearerAuth: [] + parameters: + - name: id + in: path + description: 'The cohort id' + required: true + schema: + type: integer + responses: + '201': + description: success + content: + application/json: + schema: + type: object + properties: + status: + type: string + data: + properties: + cohort: + $ref: '#/components/schemas/Cohort' + '401': + description: Unautorized + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + '404': + description: Not Found + content: + application/json: + schema: + $ref: '#/components/schemas/Error' + '500': + description: Server error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' components: securitySchemes: @@ -460,12 +540,18 @@ components: properties: id: type: integer + cohortName: + type: string createdAt: type: string format: date-time updatedAt: type: string format: date-time + users: + type: array + items: + $ref: '#/components/schemas/User' AllUsers: type: object @@ -772,4 +858,4 @@ components: id: type: integer content: - type: string + type: string \ No newline at end of file From 5026ae487da0a87af408774aef1bd8a38de2ab69 Mon Sep 17 00:00:00 2001 From: Jonas Halvorsen <91602910+JHalvor@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:28:07 +0100 Subject: [PATCH 08/11] Update openapi.yml --- docs/openapi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/openapi.yml b/docs/openapi.yml index 7b6d1ed2..9c9d18fa 100644 --- a/docs/openapi.yml +++ b/docs/openapi.yml @@ -858,4 +858,4 @@ components: id: type: integer content: - type: string \ No newline at end of file + type: string From 084647980f376d3d0092305ec2aa173f808b4741 Mon Sep 17 00:00:00 2001 From: JHalvor Date: Thu, 31 Oct 2024 13:32:47 +0100 Subject: [PATCH 09/11] update --- package-lock.json | 205 ++++++++++++++++------------------------------ 1 file changed, 69 insertions(+), 136 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5792fc24..044145e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@prisma/client": "^5.21.1", + "@prisma/client": "^3.12.0", "bcrypt": "^5.0.1", "cors": "^2.8.5", "dotenv": "^16.0.0", @@ -27,9 +27,10 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^4.0.0", "eslint-plugin-promise": "^5.1.0", + "husky": "^7.0.4", "nodemon": "^2.0.15", "prettier": "^2.6.2", - "prisma": "^5.21.1" + "prisma": "^3.12.0" } }, "node_modules/@babel/code-frame": { @@ -201,13 +202,15 @@ } }, "node_modules/@prisma/client": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.21.1.tgz", - "integrity": "sha512-3n+GgbAZYjaS/k0M03yQsQfR1APbr411r74foknnsGpmhNKBG49VuUkxIU6jORgvJPChoD4WC4PqoHImN1FP0w==", + "version": "3.15.2", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-3.15.2.tgz", + "integrity": "sha512-ErqtwhX12ubPhU4d++30uFY/rPcyvjk+mdifaZO5SeM21zS3t4jQrscy8+6IyB0GIYshl5ldTq6JSBo1d63i8w==", "hasInstallScript": true, - "license": "Apache-2.0", + "dependencies": { + "@prisma/engines-version": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" + }, "engines": { - "node": ">=16.13" + "node": ">=12.6" }, "peerDependencies": { "prisma": "*" @@ -218,62 +221,17 @@ } } }, - "node_modules/@prisma/debug": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.21.1.tgz", - "integrity": "sha512-uY8SAhcnORhvgtOrNdvWS98Aq/nkQ9QDUxrWAgW8XrCZaI3j2X7zb7Xe6GQSh6xSesKffFbFlkw0c2luHQviZA==", - "devOptional": true, - "license": "Apache-2.0" - }, "node_modules/@prisma/engines": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.21.1.tgz", - "integrity": "sha512-hGVTldUkIkTwoV8//hmnAAiAchi4oMEKD3aW5H2RrnI50tTdwza7VQbTTAyN3OIHWlK5DVg6xV7X8N/9dtOydA==", - "devOptional": true, - "hasInstallScript": true, - "license": "Apache-2.0", - "dependencies": { - "@prisma/debug": "5.21.1", - "@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", - "@prisma/fetch-engine": "5.21.1", - "@prisma/get-platform": "5.21.1" - } - }, - "node_modules/@prisma/engines/node_modules/@prisma/engines-version": { - "version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36.tgz", - "integrity": "sha512-qvnEflL0//lh44S/T9NcvTMxfyowNeUxTunPcDfKPjyJNrCNf2F1zQLcUv5UHAruECpX+zz21CzsC7V2xAeM7Q==", - "devOptional": true, - "license": "Apache-2.0" - }, - "node_modules/@prisma/fetch-engine": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.21.1.tgz", - "integrity": "sha512-70S31vgpCGcp9J+mh/wHtLCkVezLUqe/fGWk3J3JWZIN7prdYSlr1C0niaWUyNK2VflLXYi8kMjAmSxUVq6WGQ==", - "devOptional": true, - "license": "Apache-2.0", - "dependencies": { - "@prisma/debug": "5.21.1", - "@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", - "@prisma/get-platform": "5.21.1" - } - }, - "node_modules/@prisma/fetch-engine/node_modules/@prisma/engines-version": { - "version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36.tgz", - "integrity": "sha512-qvnEflL0//lh44S/T9NcvTMxfyowNeUxTunPcDfKPjyJNrCNf2F1zQLcUv5UHAruECpX+zz21CzsC7V2xAeM7Q==", + "version": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz", + "integrity": "sha512-NHlojO1DFTsSi3FtEleL9QWXeSF/UjhCW0fgpi7bumnNZ4wj/eQ+BJJ5n2pgoOliTOGv9nX2qXvmHap7rJMNmg==", "devOptional": true, - "license": "Apache-2.0" + "hasInstallScript": true }, - "node_modules/@prisma/get-platform": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.21.1.tgz", - "integrity": "sha512-sRxjL3Igst3ct+e8ya/x//cDXmpLbZQ5vfps2N4tWl4VGKQAmym77C/IG/psSMsQKszc8uFC/q1dgmKFLUgXZQ==", - "devOptional": true, - "license": "Apache-2.0", - "dependencies": { - "@prisma/debug": "5.21.1" - } + "node_modules/@prisma/engines-version": { + "version": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz", + "integrity": "sha512-e3k2Vd606efd1ZYy2NQKkT4C/pn31nehyLhVug6To/q8JT8FpiMrDy7zmm3KLF0L98NOQQcutaVtAPhzKhzn9w==" }, "node_modules/@types/json5": { "version": "0.0.29", @@ -1563,12 +1521,11 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "dev": true, "hasInstallScript": true, - "license": "MIT", "optional": true, "os": [ "darwin" @@ -1808,6 +1765,21 @@ "node": ">= 6" } }, + "node_modules/husky": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/husky/-/husky-7.0.4.tgz", + "integrity": "sha512-vbaCKN2QLtP/vD4yvs6iz6hBEo6wkSzs8HpRah1Z6aGmF2KW5PdYuAd7uX5a+OyBZHBhd+TFLqgjUgytQr4RvQ==", + "dev": true, + "bin": { + "husky": "lib/bin.js" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -2793,23 +2765,20 @@ } }, "node_modules/prisma": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.21.1.tgz", - "integrity": "sha512-PB+Iqzld/uQBPaaw2UVIk84kb0ITsLajzsxzsadxxl54eaU5Gyl2/L02ysivHxK89t7YrfQJm+Ggk37uvM70oQ==", + "version": "3.15.2", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-3.15.2.tgz", + "integrity": "sha512-nMNSMZvtwrvoEQ/mui8L/aiCLZRCj5t6L3yujKpcDhIPk7garp8tL4nMx2+oYsN0FWBacevJhazfXAbV1kfBzA==", "devOptional": true, "hasInstallScript": true, - "license": "Apache-2.0", "dependencies": { - "@prisma/engines": "5.21.1" + "@prisma/engines": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" }, "bin": { - "prisma": "build/index.js" + "prisma": "build/index.js", + "prisma2": "build/index.js" }, "engines": { - "node": ">=16.13" - }, - "optionalDependencies": { - "fsevents": "2.3.3" + "node": ">=12.6" } }, "node_modules/progress": { @@ -3753,64 +3722,23 @@ } }, "@prisma/client": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.21.1.tgz", - "integrity": "sha512-3n+GgbAZYjaS/k0M03yQsQfR1APbr411r74foknnsGpmhNKBG49VuUkxIU6jORgvJPChoD4WC4PqoHImN1FP0w==", - "requires": {} - }, - "@prisma/debug": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.21.1.tgz", - "integrity": "sha512-uY8SAhcnORhvgtOrNdvWS98Aq/nkQ9QDUxrWAgW8XrCZaI3j2X7zb7Xe6GQSh6xSesKffFbFlkw0c2luHQviZA==", - "devOptional": true - }, - "@prisma/engines": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.21.1.tgz", - "integrity": "sha512-hGVTldUkIkTwoV8//hmnAAiAchi4oMEKD3aW5H2RrnI50tTdwza7VQbTTAyN3OIHWlK5DVg6xV7X8N/9dtOydA==", - "devOptional": true, + "version": "3.15.2", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-3.15.2.tgz", + "integrity": "sha512-ErqtwhX12ubPhU4d++30uFY/rPcyvjk+mdifaZO5SeM21zS3t4jQrscy8+6IyB0GIYshl5ldTq6JSBo1d63i8w==", "requires": { - "@prisma/debug": "5.21.1", - "@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", - "@prisma/fetch-engine": "5.21.1", - "@prisma/get-platform": "5.21.1" - }, - "dependencies": { - "@prisma/engines-version": { - "version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36.tgz", - "integrity": "sha512-qvnEflL0//lh44S/T9NcvTMxfyowNeUxTunPcDfKPjyJNrCNf2F1zQLcUv5UHAruECpX+zz21CzsC7V2xAeM7Q==", - "devOptional": true - } + "@prisma/engines-version": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" } }, - "@prisma/fetch-engine": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.21.1.tgz", - "integrity": "sha512-70S31vgpCGcp9J+mh/wHtLCkVezLUqe/fGWk3J3JWZIN7prdYSlr1C0niaWUyNK2VflLXYi8kMjAmSxUVq6WGQ==", - "devOptional": true, - "requires": { - "@prisma/debug": "5.21.1", - "@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", - "@prisma/get-platform": "5.21.1" - }, - "dependencies": { - "@prisma/engines-version": { - "version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36.tgz", - "integrity": "sha512-qvnEflL0//lh44S/T9NcvTMxfyowNeUxTunPcDfKPjyJNrCNf2F1zQLcUv5UHAruECpX+zz21CzsC7V2xAeM7Q==", - "devOptional": true - } - } + "@prisma/engines": { + "version": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz", + "integrity": "sha512-NHlojO1DFTsSi3FtEleL9QWXeSF/UjhCW0fgpi7bumnNZ4wj/eQ+BJJ5n2pgoOliTOGv9nX2qXvmHap7rJMNmg==", + "devOptional": true }, - "@prisma/get-platform": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.21.1.tgz", - "integrity": "sha512-sRxjL3Igst3ct+e8ya/x//cDXmpLbZQ5vfps2N4tWl4VGKQAmym77C/IG/psSMsQKszc8uFC/q1dgmKFLUgXZQ==", - "devOptional": true, - "requires": { - "@prisma/debug": "5.21.1" - } + "@prisma/engines-version": { + "version": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e.tgz", + "integrity": "sha512-e3k2Vd606efd1ZYy2NQKkT4C/pn31nehyLhVug6To/q8JT8FpiMrDy7zmm3KLF0L98NOQQcutaVtAPhzKhzn9w==" }, "@types/json5": { "version": "0.0.29", @@ -4794,9 +4722,9 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, "fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", "dev": true, "optional": true }, @@ -4965,6 +4893,12 @@ "debug": "4" } }, + "husky": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/husky/-/husky-7.0.4.tgz", + "integrity": "sha512-vbaCKN2QLtP/vD4yvs6iz6hBEo6wkSzs8HpRah1Z6aGmF2KW5PdYuAd7uX5a+OyBZHBhd+TFLqgjUgytQr4RvQ==", + "dev": true + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -5682,13 +5616,12 @@ } }, "prisma": { - "version": "5.21.1", - "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.21.1.tgz", - "integrity": "sha512-PB+Iqzld/uQBPaaw2UVIk84kb0ITsLajzsxzsadxxl54eaU5Gyl2/L02ysivHxK89t7YrfQJm+Ggk37uvM70oQ==", + "version": "3.15.2", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-3.15.2.tgz", + "integrity": "sha512-nMNSMZvtwrvoEQ/mui8L/aiCLZRCj5t6L3yujKpcDhIPk7garp8tL4nMx2+oYsN0FWBacevJhazfXAbV1kfBzA==", "devOptional": true, "requires": { - "@prisma/engines": "5.21.1", - "fsevents": "2.3.3" + "@prisma/engines": "3.15.1-1.461d6a05159055555eb7dfb337c9fb271cbd4d7e" } }, "progress": { From 551596816dab557c457927e82883caacf514b195 Mon Sep 17 00:00:00 2001 From: Jonas Halvorsen <91602910+JHalvor@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:35:32 +0100 Subject: [PATCH 10/11] Update openapi.yml From ab2fd93637b933b51adb7ce2cfb894e2ab749853 Mon Sep 17 00:00:00 2001 From: Jonas Halvorsen <91602910+JHalvor@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:37:22 +0100 Subject: [PATCH 11/11] Update openapi.yml --- docs/openapi.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/openapi.yml b/docs/openapi.yml index 9c9d18fa..099f747e 100644 --- a/docs/openapi.yml +++ b/docs/openapi.yml @@ -2,10 +2,10 @@ openapi: 3.0.3 info: title: Team Dev Server API description: |- - version: '1.0' + version: "1.0" servers: - - url: 'http://localhost:4000/' + - url: "http://localhost:4000/" tags: - name: user - name: post @@ -168,7 +168,7 @@ paths: schema: $ref: '#/components/schemas/Error' '400': - description: Invalid email/password/profile information supplied + description: Invalid email/password supplied content: application/json: schema: