Commit 30fe0922 authored by rlacko's avatar rlacko 💬
Browse files

update user url and add documentation

parent 2cc795d4
Pipeline #4703 failed with stages
in 2 minutes and 24 seconds
......@@ -7,9 +7,9 @@
},
"runOnChangeOnly": false,
"watch": ["src/**/*.js"],
"watch": ["src/**/*"],
"env": {
"NODE_ENV": "development"
},
"ext": "js,json"
"ext": "js,json,yml"
}
......@@ -4,6 +4,40 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@apidevtools/json-schema-ref-parser": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-8.0.0.tgz",
"integrity": "sha512-n4YBtwQhdpLto1BaUCyAeflizmIbaloGShsPyRtFf5qdFJxfssj+GgLavczgKJFa3Bq+3St2CKcpRJdjtB4EBw==",
"requires": {
"@jsdevtools/ono": "^7.1.0",
"call-me-maybe": "^1.0.1",
"js-yaml": "^3.13.1"
}
},
"@apidevtools/openapi-schemas": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/@apidevtools/openapi-schemas/-/openapi-schemas-2.0.4.tgz",
"integrity": "sha512-ob5c4UiaMYkb24pNhvfSABShAwpREvUGCkqjiz/BX9gKZ32y/S22M+ALIHftTAuv9KsFVSpVdIDzi9ZzFh5TCA=="
},
"@apidevtools/swagger-methods": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/@apidevtools/swagger-methods/-/swagger-methods-3.0.2.tgz",
"integrity": "sha512-QAkD5kK2b1WfjDS/UQn/qQkbwF31uqRjPTrsCs5ZG9BQGAkjwvqGFjjPqAuzac/IYzpPtRzjCP1WrTuAIjMrXg=="
},
"@apidevtools/swagger-parser": {
"version": "9.0.1",
"resolved": "https://registry.npmjs.org/@apidevtools/swagger-parser/-/swagger-parser-9.0.1.tgz",
"integrity": "sha512-Irqybg4dQrcHhZcxJc/UM4vO7Ksoj1Id5e+K94XUOzllqX1n47HEA50EKiXTCQbykxuJ4cYGIivjx/MRSTC5OA==",
"requires": {
"@apidevtools/json-schema-ref-parser": "^8.0.0",
"@apidevtools/openapi-schemas": "^2.0.2",
"@apidevtools/swagger-methods": "^3.0.0",
"@jsdevtools/ono": "^7.1.0",
"call-me-maybe": "^1.0.1",
"openapi-types": "^1.3.5",
"z-schema": "^4.2.2"
}
},
"@babel/code-frame": {
"version": "7.10.4",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz",
......@@ -627,6 +661,11 @@
"chalk": "^4.0.0"
}
},
"@jsdevtools/ono": {
"version": "7.1.3",
"resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz",
"integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg=="
},
"@sindresorhus/is": {
"version": "0.14.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz",
......@@ -1043,7 +1082,6 @@
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
"dev": true,
"requires": {
"sprintf-js": "~1.0.2"
}
......@@ -1209,8 +1247,7 @@
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
"dev": true
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"base": {
"version": "0.11.2",
......@@ -1427,7 +1464,6 @@
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
......@@ -1522,6 +1558,11 @@
}
}
},
"call-me-maybe": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/call-me-maybe/-/call-me-maybe-1.0.1.tgz",
"integrity": "sha1-JtII6onje1y95gJQoV8DHBak1ms="
},
"callsites": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
......@@ -1755,6 +1796,11 @@
"delayed-stream": "~1.0.0"
}
},
"commander": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-5.0.0.tgz",
"integrity": "sha512-JrDGPAKjMGSP1G0DUoaceEJ3DZgAfr/q6X7FVk4+U5KxUSKviYGM2k6zWkfyyBHy5rAtzgYJFa1ro2O9PtoxwQ=="
},
"commondir": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
......@@ -1770,8 +1816,7 @@
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"dev": true
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"configstore": {
"version": "5.0.1",
......@@ -2091,7 +2136,6 @@
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz",
"integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==",
"dev": true,
"requires": {
"esutils": "^2.0.2"
}
......@@ -2513,8 +2557,7 @@
"esprima": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
"dev": true
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
},
"esquery": {
"version": "1.3.1",
......@@ -2551,8 +2594,7 @@
"esutils": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",
"integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==",
"dev": true
"integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g=="
},
"etag": {
"version": "1.8.1",
......@@ -3036,8 +3078,7 @@
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
"dev": true
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"fsevents": {
"version": "2.1.3",
......@@ -3104,7 +3145,6 @@
"version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
......@@ -3373,7 +3413,6 @@
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dev": true,
"requires": {
"once": "^1.3.0",
"wrappy": "1"
......@@ -4269,7 +4308,6 @@
"version": "3.14.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.0.tgz",
"integrity": "sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A==",
"dev": true,
"requires": {
"argparse": "^1.0.7",
"esprima": "^4.0.0"
......@@ -4477,6 +4515,16 @@
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ=="
},
"lodash.get": {
"version": "4.4.2",
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
},
"lodash.isequal": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
"integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA="
},
"lodash.sortby": {
"version": "4.7.0",
"resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
......@@ -4601,7 +4649,6 @@
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"dev": true,
"requires": {
"brace-expansion": "^1.1.7"
}
......@@ -4998,7 +5045,6 @@
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"dev": true,
"requires": {
"wrappy": "1"
}
......@@ -5012,6 +5058,11 @@
"mimic-fn": "^2.1.0"
}
},
"openapi-types": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/openapi-types/-/openapi-types-1.3.5.tgz",
"integrity": "sha512-11oi4zYorsgvg5yBarZplAqbpev5HkuVNPlZaPTknPDzAynq+lnJdXAmruGWP0s+dNYZS7bjM+xrTpJw7184Fg=="
},
"optionator": {
"version": "0.9.1",
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz",
......@@ -5173,8 +5224,7 @@
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
},
"path-key": {
"version": "3.1.1",
......@@ -6248,8 +6298,7 @@
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
"dev": true
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
},
"sshpk": {
"version": "1.16.1",
......@@ -6486,6 +6535,50 @@
}
}
},
"swagger-jsdoc": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/swagger-jsdoc/-/swagger-jsdoc-4.0.0.tgz",
"integrity": "sha512-wHrmRvE/OQa3d387YIrRNPvsPwxkJc0tAYeCVa359gUIKPjC4ReduFhqq/+4erLUS79kY1T5Fv0hE0SV/PgBig==",
"requires": {
"commander": "5.0.0",
"doctrine": "3.0.0",
"glob": "7.1.6",
"js-yaml": "3.13.1",
"swagger-parser": "9.0.1"
},
"dependencies": {
"js-yaml": {
"version": "3.13.1",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz",
"integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==",
"requires": {
"argparse": "^1.0.7",
"esprima": "^4.0.0"
}
}
}
},
"swagger-parser": {
"version": "9.0.1",
"resolved": "https://registry.npmjs.org/swagger-parser/-/swagger-parser-9.0.1.tgz",
"integrity": "sha512-oxOHUaeNetO9ChhTJm2fD+48DbGbLD09ZEOwPOWEqcW8J6zmjWxutXtSuOiXsoRgDWvORYlImbwM21Pn+EiuvQ==",
"requires": {
"@apidevtools/swagger-parser": "9.0.1"
}
},
"swagger-ui-dist": {
"version": "3.30.2",
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.30.2.tgz",
"integrity": "sha512-hAu/ig5N8i0trXXbrC7rwbXV4DhpEAsZhYXDs1305OjmDgjGC0thINbb0197idy3Pp+B6w7u426SUM43GAP7qw=="
},
"swagger-ui-express": {
"version": "4.1.4",
"resolved": "https://registry.npmjs.org/swagger-ui-express/-/swagger-ui-express-4.1.4.tgz",
"integrity": "sha512-Ea96ecpC+Iq9GUqkeD/LFR32xSs8gYqmTW1gXCuKg81c26WV6ZC2FsBSPVExQP6WkyUuz5HEiR0sEv/HCC343g==",
"requires": {
"swagger-ui-dist": "^3.18.1"
}
},
"symbol-tree": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz",
......@@ -7158,8 +7251,7 @@
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"write": {
"version": "1.0.3",
......@@ -7288,6 +7380,30 @@
"dev": true
}
}
},
"z-schema": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/z-schema/-/z-schema-4.2.3.tgz",
"integrity": "sha512-zkvK/9TC6p38IwcrbnT3ul9in1UX4cm1y/VZSs4GHKIiDCrlafc+YQBgQBUdDXLAoZHf2qvQ7gJJOo6yT1LH6A==",
"requires": {
"commander": "^2.7.1",
"lodash.get": "^4.4.2",
"lodash.isequal": "^4.5.0",
"validator": "^12.0.0"
},
"dependencies": {
"commander": {
"version": "2.20.3",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"optional": true
},
"validator": {
"version": "12.2.0",
"resolved": "https://registry.npmjs.org/validator/-/validator-12.2.0.tgz",
"integrity": "sha512-jJfE/DW6tIK1Ek8nCfNFqt8Wb3nzMoAbocBF6/Icgg1ZFSBpObdnwVY2jQj6qUqzhx5jc71fpvBWyLGO7Xl+nQ=="
}
}
}
}
}
......@@ -28,6 +28,8 @@
"morgan": "^1.10.0",
"passport": "^0.4.1",
"passport-oauth2": "^1.5.0",
"swagger-jsdoc": "^4.0.0",
"swagger-ui-express": "^4.1.4",
"validator": "^13.1.1"
},
"devDependencies": {
......
......@@ -60,7 +60,7 @@ module.exports.createOne = async function createOne(req, res) {
return res
.status(200)
.json({
data: pick(populatedActivity, pickedKeys),
data: pick(activity, pickedKeys),
})
.end()
} catch (err) {
......
openapi: '3.0.2'
info:
title: Activity Endpoint
version: '1.0'
components:
schemas:
Activity:
type: object
properties:
property:
type: integer
paths:
/activity:
get:
responses:
'400':
description: OK
const { Router } = require('express')
const { isLoggedIn } = require('../../middlewares/auth')
const { getOne, updateOne } = require('../user/userControllers').default
const router = Router()
// /api/v1/extra/me
router
.route('/me') // Tested in user
.get(isLoggedIn, async (req, res) => {
req.params.id = req.user.schacc
await getOne(req, res)
})
.put(isLoggedIn, async (req, res) => {
req.params.id = req.user.schacc
await updateOne(req, res)
})
exports.default = router
......@@ -42,7 +42,9 @@ describe('/user "Mentor" Functionality', () => {
// GET One
test(`GET one returns with allowed keys`, async () => {
let newUser = await User.create(fakeUserJson)
let response = await authSession.get(`${endpointUrl}/${newUser.schacc}`)
let response = await authSession.get(
`${endpointUrl}/schacc/${newUser.schacc}`
)
expect(response.statusCode).toBe(200)
validateKeys(
......@@ -52,11 +54,11 @@ describe('/user "Mentor" Functionality', () => {
newUser = await User.create(
Object.assign({}, fakeUserJson, { imagePath: 'almafa', schacc: 'apple' })
)
response = await authSession.get(`${endpointUrl}/${newUser.schacc}`)
response = await authSession.get(`${endpointUrl}/schacc/${newUser.schacc}`)
expect(has(response.body.data, 'imagePath')).toBe(true)
})
test(`GET own user returns with allowed keys`, async () => {
const response = await authSession.get(`/api/v1/extra/me`)
const response = await authSession.get(`${endpointUrl}/me`)
expect(response.statusCode).toBe(200)
validateKeys(
......@@ -79,7 +81,9 @@ describe('/user "Mentor" Functionality', () => {
// SoftDelete
test(`Delete user returns with allowed keys`, async () => {
const newUser = await User.create(fakeUserJson)
let response = await authSession.delete(`${endpointUrl}/${newUser.schacc}`)
let response = await authSession.delete(
`${endpointUrl}/schacc/${newUser.schacc}`
)
expect(response.statusCode).toBe(200)
validateKeys(
response.body.data,
......@@ -92,7 +96,7 @@ describe('/user "Mentor" Functionality', () => {
test(`Update user returns with allowed keys`, async () => {
const newUser = await User.create(fakeUserJson)
let response = await authSession
.put(`${endpointUrl}/${newUser.schacc}`)
.put(`${endpointUrl}/schacc/${newUser.schacc}`)
.send({
fullName: 'Janos',
secondaryEmail: 'jani@gmail.com',
......@@ -119,7 +123,7 @@ describe('/user "Mentor" Functionality', () => {
test(`Update with invalid email`, async () => {
const newUser = await User.create(fakeUserJson)
let response = await authSession
.put(`${endpointUrl}/${newUser.schacc}`)
.put(`${endpointUrl}/schacc/${newUser.schacc}`)
.send({
secondaryEmail: 'testemail',
})
......@@ -140,13 +144,13 @@ describe('/user "Accepted" Functionality', () => {
})
// GET One
test(`GET own user returns with allowed keys`, async () => {
const response = await authSession.get(`/api/v1/extra/me`)
const response = await authSession.get(`${endpointUrl}/me`)
expect(response.statusCode).toBe(200)
validateKeys(response.body.data, defaultKeys)
})
// Update own user
test(`Update own user returns with allowed keys`, async () => {
let response = await authSession.put(`/api/v1/extra/me`).send({
let response = await authSession.put(`${endpointUrl}/me`).send({
fullName: 'Janos',
secondaryEmail: 'jani@gmail.com',
bit: 10,
......@@ -185,13 +189,13 @@ describe('/user "Normal" Functionality', () => {
})
// GET One
test(`GET own user returns with allowed keys`, async () => {
const response = await authSession.get(`/api/v1/extra/me`)
const response = await authSession.get(`${endpointUrl}/me`)
expect(response.statusCode).toBe(200)
validateKeys(response.body.data, defaultKeys)
})
// Update own user
test(`Update own user returns with allowed keys`, async () => {
let response = await authSession.put(`/api/v1/extra/me`).send({
let response = await authSession.put(`${endpointUrl}/me`).send({
fullName: 'Janos',
secondaryEmail: 'jani@gmail.com',
bit: 10,
......
......@@ -17,11 +17,11 @@ describe('/user Permission tests', () => {
let authSession
crudPermTest(
app,
endpointUrl,
endpointUrl + '/schacc',
User,
'user',
fakeUserJson,
[false, true, true, true, true],
[false, false, true, true, true],
[
// [role, create, readAll, readOne, update, delete]
['none', false, false, false, false, false],
......@@ -41,14 +41,33 @@ describe('/user Permission tests', () => {
})
})
// All roles
test(`Can Get own user on /:id or on /me`, async () => {
test(`Can Get own user on own /schacc/{schacc} or on /me`, async () => {
user = await User.findOne().lean().exec()
let response = await authSession.get(`${endpointUrl}/${user.schacc}`)
let response = await authSession.get(
`${endpointUrl}/schacc/${user.schacc}`
)
expect(response.statusCode).toBe(200)
expect(response.body.data.schacc).toBe(user.schacc)
response = await authSession.get(`/api/v1/extra/me`)
response = await authSession.get(`${endpointUrl}/me`)
expect(response.statusCode).toBe(200)
expect(response.body.data.schacc).toBe(user.schacc)
})
})
crudPermTest(
app,
endpointUrl,
User,
'user',
fakeUserJson,
[false, true, false, false, false],
[
// [role, create, readAll, readOne, update, delete]
['none', false, false, false, false, false],
['normal', false, false, false, false, false],
['accepted', false, false, false, false, false],
['mentor', false, true, true, true, true],
],
{ schacc: 'alma' }
)
})
......@@ -29,18 +29,16 @@ const getUpdateKeysByRole = (role) => {
return notMentorKeys
}
exports.default = crudControllers(User, defaultKeys)
exports.default.getOne = async (req, res) => {
module.exports.getOne = async (req, res) => {
try {
// Get Own User
if (req.params.id === req.user.schacc && req.user.role !== 'mentor')
if (req.params.schacc === req.user.schacc && req.user.role !== 'mentor')
return res.status(200).json({ data: pick(req.user, defaultKeys) })
// Get Other User
if (req.user.role !== 'mentor') return res.status(403).end()
const userSchacc = req.params.id
const userSchacc = req.params.schacc
// Get user from db
const user = await User.findOne({ schacc: userSchacc }).lean().exec()
......@@ -61,13 +59,13 @@ exports.default.getOne = async (req, res) => {
}
// Overwrite the returned keys
exports.default.getMany = getMany(User, [...defaultKeys, 'bit', 'presence'])
module.exports.getMany = getMany(User, [...defaultKeys, 'bit', 'presence'])
// Doesn't delete the user just disable it
exports.default.softRemove = async (req, res) => {
module.exports.softRemove = async (req, res) => {
try {
let user = await User.findOneAndUpdate(
{ schacc: req.params.id },
{ schacc: req.params.schacc },
{
valid: false,
receiveMail: false,
......@@ -90,12 +88,12 @@ exports.default.softRemove = async (req, res) => {
}
}
exports.default.updateOne = async (req, res) => {
module.exports.updateOne = async (req, res) => {
try {
if (!(req.params.id === req.user.schacc || req.user.role === 'mentor'))
if (!(req.params.schacc === req.user.schacc || req.user.role === 'mentor'))
return res.status(403).end()
const userSchacc = req.params.id
const userSchacc = req.params.schacc
// Update with given keys
const updatedUser = await User.findOneAndUpdate(
......
openapi: '3.0.2'
info:
title: 'User Endpoint'
version: '1.0'
paths:
/user:
get:
tags:
- 'User'
summary: 'Get a List of users'
description: 'This can only be done by a mentor.'
operationId: 'getAllUser'
responses:
'200':
description: OK
content:
application/json:
schema: