diff --git a/package.json b/package.json index 0371f5da..56c05736 100644 --- a/package.json +++ b/package.json @@ -67,8 +67,8 @@ "passport": "^0.4.0", "passport-jwt": "^4.0.0", "pm2": "^4.1.2", - "swagger-jsdoc": "4.2.0", - "swagger-ui-express": "4.1.4", + "swagger-jsdoc": "^6.0.8", + "swagger-ui-express": "^4.1.6", "validator": "^13.0.0", "winston": "^3.2.1", "xss-clean": "^0.1.1" diff --git a/src/routes/v1/auth.route.js b/src/routes/v1/auth.route.js index dbd2cee2..fc380a44 100644 --- a/src/routes/v1/auth.route.js +++ b/src/routes/v1/auth.route.js @@ -23,229 +23,223 @@ module.exports = router; /** * @swagger - * path: - * /auth/register: - * post: - * summary: Register as user - * tags: [Auth] - * requestBody: - * required: true - * content: - * application/json: - * schema: - * type: object - * required: - * - name - * - email - * - password - * properties: - * name: - * type: string - * email: - * type: string - * format: email - * description: must be unique - * password: - * type: string - * format: password - * minLength: 8 - * description: At least one number and one letter - * example: - * name: fake name - * email: fake@example.com - * password: password1 - * responses: - * "201": - * description: Created - * content: - * application/json: - * schema: - * type: object - * properties: - * user: - * $ref: '#/components/schemas/User' - * tokens: - * $ref: '#/components/schemas/AuthTokens' - * "400": - * $ref: '#/components/responses/DuplicateEmail' + * /auth/register: + * post: + * summary: Register as user + * tags: [Auth] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * required: + * - name + * - email + * - password + * properties: + * name: + * type: string + * email: + * type: string + * format: email + * description: must be unique + * password: + * type: string + * format: password + * minLength: 8 + * description: At least one number and one letter + * example: + * name: fake name + * email: fake@example.com + * password: password1 + * responses: + * "201": + * description: Created + * content: + * application/json: + * schema: + * type: object + * properties: + * user: + * $ref: '#/components/schemas/User' + * tokens: + * $ref: '#/components/schemas/AuthTokens' + * "400": + * $ref: '#/components/responses/DuplicateEmail' */ /** * @swagger - * path: - * /auth/login: - * post: - * summary: Login - * tags: [Auth] - * requestBody: - * required: true - * content: - * application/json: - * schema: - * type: object - * required: - * - email - * - password - * properties: - * email: - * type: string - * format: email - * password: - * type: string - * format: password - * example: - * email: fake@example.com - * password: password1 - * responses: - * "200": - * description: OK - * content: - * application/json: - * schema: - * type: object - * properties: - * user: - * $ref: '#/components/schemas/User' - * tokens: - * $ref: '#/components/schemas/AuthTokens' - * "401": - * description: Invalid email or password - * content: - * application/json: - * schema: - * $ref: '#/components/schemas/Error' - * example: - * code: 401 - * message: Invalid email or password + * /auth/login: + * post: + * summary: Login + * tags: [Auth] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * required: + * - email + * - password + * properties: + * email: + * type: string + * format: email + * password: + * type: string + * format: password + * example: + * email: fake@example.com + * password: password1 + * responses: + * "200": + * description: OK + * content: + * application/json: + * schema: + * type: object + * properties: + * user: + * $ref: '#/components/schemas/User' + * tokens: + * $ref: '#/components/schemas/AuthTokens' + * "401": + * description: Invalid email or password + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' + * example: + * code: 401 + * message: Invalid email or password */ /** * @swagger - * path: - * /auth/logout: - * post: - * summary: Logout - * tags: [Auth] - * requestBody: - * required: true - * content: - * application/json: - * schema: - * type: object - * required: - * - refreshToken - * properties: - * refreshToken: - * type: string - * example: - * refreshToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1ZWJhYzUzNDk1NGI1NDEzOTgwNmMxMTIiLCJpYXQiOjE1ODkyOTg0ODQsImV4cCI6MTU4OTMwMDI4NH0.m1U63blB0MLej_WfB7yC2FTMnCziif9X8yzwDEfJXAg - * responses: - * "204": - * description: No content - * "404": - * $ref: '#/components/responses/NotFound' + * /auth/logout: + * post: + * summary: Logout + * tags: [Auth] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * required: + * - refreshToken + * properties: + * refreshToken: + * type: string + * example: + * refreshToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1ZWJhYzUzNDk1NGI1NDEzOTgwNmMxMTIiLCJpYXQiOjE1ODkyOTg0ODQsImV4cCI6MTU4OTMwMDI4NH0.m1U63blB0MLej_WfB7yC2FTMnCziif9X8yzwDEfJXAg + * responses: + * "204": + * description: No content + * "404": + * $ref: '#/components/responses/NotFound' */ /** * @swagger - * path: - * /auth/refresh-tokens: - * post: - * summary: Refresh auth tokens - * tags: [Auth] - * requestBody: - * required: true - * content: - * application/json: - * schema: - * type: object - * required: - * - refreshToken - * properties: - * refreshToken: - * type: string - * example: - * refreshToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1ZWJhYzUzNDk1NGI1NDEzOTgwNmMxMTIiLCJpYXQiOjE1ODkyOTg0ODQsImV4cCI6MTU4OTMwMDI4NH0.m1U63blB0MLej_WfB7yC2FTMnCziif9X8yzwDEfJXAg - * responses: - * "200": - * description: OK - * content: - * application/json: - * schema: - * $ref: '#/components/schemas/AuthTokens' - * "401": - * $ref: '#/components/responses/Unauthorized' + * /auth/refresh-tokens: + * post: + * summary: Refresh auth tokens + * tags: [Auth] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * required: + * - refreshToken + * properties: + * refreshToken: + * type: string + * example: + * refreshToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1ZWJhYzUzNDk1NGI1NDEzOTgwNmMxMTIiLCJpYXQiOjE1ODkyOTg0ODQsImV4cCI6MTU4OTMwMDI4NH0.m1U63blB0MLej_WfB7yC2FTMnCziif9X8yzwDEfJXAg + * responses: + * "200": + * description: OK + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/AuthTokens' + * "401": + * $ref: '#/components/responses/Unauthorized' */ /** * @swagger - * path: - * /auth/forgot-password: - * post: - * summary: Forgot password - * description: An email will be sent to reset password. - * tags: [Auth] - * requestBody: - * required: true - * content: - * application/json: - * schema: - * type: object - * required: - * - email - * properties: - * email: - * type: string - * format: email - * example: - * email: fake@example.com - * responses: - * "204": - * description: No content - * "404": - * $ref: '#/components/responses/NotFound' + * /auth/forgot-password: + * post: + * summary: Forgot password + * description: An email will be sent to reset password. + * tags: [Auth] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * required: + * - email + * properties: + * email: + * type: string + * format: email + * example: + * email: fake@example.com + * responses: + * "204": + * description: No content + * "404": + * $ref: '#/components/responses/NotFound' */ /** * @swagger - * path: - * /auth/reset-password: - * post: - * summary: Reset password - * tags: [Auth] - * parameters: - * - in: query - * name: token - * required: true - * schema: - * type: string - * description: The reset password token - * requestBody: - * required: true - * content: - * application/json: - * schema: - * type: object - * required: - * - password - * properties: - * password: - * type: string - * format: password - * minLength: 8 - * description: At least one number and one letter - * example: - * password: password1 - * responses: - * "204": - * description: No content - * "401": - * description: Password reset failed - * content: - * application/json: - * schema: - * $ref: '#/components/schemas/Error' - * example: - * code: 401 - * message: Password reset failed + * /auth/reset-password: + * post: + * summary: Reset password + * tags: [Auth] + * parameters: + * - in: query + * name: token + * required: true + * schema: + * type: string + * description: The reset password token + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * required: + * - password + * properties: + * password: + * type: string + * format: password + * minLength: 8 + * description: At least one number and one letter + * example: + * password: password1 + * responses: + * "204": + * description: No content + * "401": + * description: Password reset failed + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' + * example: + * code: 401 + * message: Password reset failed */ diff --git a/src/routes/v1/user.route.js b/src/routes/v1/user.route.js index c4cfee83..a0a329c4 100644 --- a/src/routes/v1/user.route.js +++ b/src/routes/v1/user.route.js @@ -28,227 +28,225 @@ module.exports = router; /** * @swagger - * path: - * /users: - * post: - * summary: Create a user - * description: Only admins can create other users. - * tags: [Users] - * security: - * - bearerAuth: [] - * requestBody: - * required: true - * content: - * application/json: - * schema: - * type: object - * required: - * - name - * - email - * - password - * - role - * properties: - * name: + * /users: + * post: + * summary: Create a user + * description: Only admins can create other users. + * tags: [Users] + * security: + * - bearerAuth: [] + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * required: + * - name + * - email + * - password + * - role + * properties: + * name: + * type: string + * email: + * type: string + * format: email + * description: must be unique + * password: + * type: string + * format: password + * minLength: 8 + * description: At least one number and one letter + * role: * type: string - * email: - * type: string - * format: email - * description: must be unique - * password: - * type: string - * format: password - * minLength: 8 - * description: At least one number and one letter - * role: - * type: string - * enum: [user, admin] - * example: - * name: fake name - * email: fake@example.com - * password: password1 - * role: user - * responses: - * "201": - * description: Created - * content: - * application/json: - * schema: - * $ref: '#/components/schemas/User' - * "400": - * $ref: '#/components/responses/DuplicateEmail' - * "401": - * $ref: '#/components/responses/Unauthorized' - * "403": - * $ref: '#/components/responses/Forbidden' + * enum: [user, admin] + * example: + * name: fake name + * email: fake@example.com + * password: password1 + * role: user + * responses: + * "201": + * description: Created + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/User' + * "400": + * $ref: '#/components/responses/DuplicateEmail' + * "401": + * $ref: '#/components/responses/Unauthorized' + * "403": + * $ref: '#/components/responses/Forbidden' * - * get: - * summary: Get all users - * description: Only admins can retrieve all users. - * tags: [Users] - * security: - * - bearerAuth: [] - * parameters: - * - in: query - * name: name - * schema: - * type: string - * description: User name - * - in: query - * name: role - * schema: - * type: string - * description: User role - * - in: query - * name: sortBy - * schema: - * type: string - * description: sort by query in the form of field:desc/asc (ex. name:asc) - * - in: query - * name: limit - * schema: - * type: integer - * minimum: 1 - * default: 10 - * description: Maximum number of users - * - in: query - * name: page - * schema: - * type: integer - * minimum: 1 - * default: 1 - * description: Page number - * responses: - * "200": - * description: OK - * content: - * application/json: - * schema: - * type: object - * properties: - * results: - * type: array - * items: - * $ref: '#/components/schemas/User' - * page: - * type: integer - * example: 1 - * limit: - * type: integer - * example: 10 - * totalPages: - * type: integer - * example: 1 - * totalResults: - * type: integer - * example: 1 - * "401": - * $ref: '#/components/responses/Unauthorized' - * "403": - * $ref: '#/components/responses/Forbidden' + * get: + * summary: Get all users + * description: Only admins can retrieve all users. + * tags: [Users] + * security: + * - bearerAuth: [] + * parameters: + * - in: query + * name: name + * schema: + * type: string + * description: User name + * - in: query + * name: role + * schema: + * type: string + * description: User role + * - in: query + * name: sortBy + * schema: + * type: string + * description: sort by query in the form of field:desc/asc (ex. name:asc) + * - in: query + * name: limit + * schema: + * type: integer + * minimum: 1 + * default: 10 + * description: Maximum number of users + * - in: query + * name: page + * schema: + * type: integer + * minimum: 1 + * default: 1 + * description: Page number + * responses: + * "200": + * description: OK + * content: + * application/json: + * schema: + * type: object + * properties: + * results: + * type: array + * items: + * $ref: '#/components/schemas/User' + * page: + * type: integer + * example: 1 + * limit: + * type: integer + * example: 10 + * totalPages: + * type: integer + * example: 1 + * totalResults: + * type: integer + * example: 1 + * "401": + * $ref: '#/components/responses/Unauthorized' + * "403": + * $ref: '#/components/responses/Forbidden' */ /** * @swagger - * path: - * /users/{id}: - * get: - * summary: Get a user - * description: Logged in users can fetch only their own user information. Only admins can fetch other users. - * tags: [Users] - * security: - * - bearerAuth: [] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * description: User id - * responses: - * "200": - * description: OK - * content: - * application/json: - * schema: - * $ref: '#/components/schemas/User' - * "401": - * $ref: '#/components/responses/Unauthorized' - * "403": - * $ref: '#/components/responses/Forbidden' - * "404": - * $ref: '#/components/responses/NotFound' + * /users/{id}: + * get: + * summary: Get a user + * description: Logged in users can fetch only their own user information. Only admins can fetch other users. + * tags: [Users] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * description: User id + * responses: + * "200": + * description: OK + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/User' + * "401": + * $ref: '#/components/responses/Unauthorized' + * "403": + * $ref: '#/components/responses/Forbidden' + * "404": + * $ref: '#/components/responses/NotFound' * - * patch: - * summary: Update a user - * description: Logged in users can only update their own information. Only admins can update other users. - * tags: [Users] - * security: - * - bearerAuth: [] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * description: User id - * requestBody: - * required: true - * content: - * application/json: - * schema: - * type: object - * properties: - * name: - * type: string - * email: - * type: string - * format: email - * description: must be unique - * password: - * type: string - * format: password - * minLength: 8 - * description: At least one number and one letter - * example: - * name: fake name - * email: fake@example.com - * password: password1 - * responses: - * "200": - * description: OK - * content: - * application/json: - * schema: - * $ref: '#/components/schemas/User' - * "400": - * $ref: '#/components/responses/DuplicateEmail' - * "401": - * $ref: '#/components/responses/Unauthorized' - * "403": - * $ref: '#/components/responses/Forbidden' - * "404": - * $ref: '#/components/responses/NotFound' + * patch: + * summary: Update a user + * description: Logged in users can only update their own information. Only admins can update other users. + * tags: [Users] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * description: User id + * requestBody: + * required: true + * content: + * application/json: + * schema: + * type: object + * properties: + * name: + * type: string + * email: + * type: string + * format: email + * description: must be unique + * password: + * type: string + * format: password + * minLength: 8 + * description: At least one number and one letter + * example: + * name: fake name + * email: fake@example.com + * password: password1 + * responses: + * "200": + * description: OK + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/User' + * "400": + * $ref: '#/components/responses/DuplicateEmail' + * "401": + * $ref: '#/components/responses/Unauthorized' + * "403": + * $ref: '#/components/responses/Forbidden' + * "404": + * $ref: '#/components/responses/NotFound' * - * delete: - * summary: Delete a user - * description: Logged in users can delete only themselves. Only admins can delete other users. - * tags: [Users] - * security: - * - bearerAuth: [] - * parameters: - * - in: path - * name: id - * required: true - * schema: - * type: string - * description: User id - * responses: - * "200": - * description: No content - * "401": - * $ref: '#/components/responses/Unauthorized' - * "403": - * $ref: '#/components/responses/Forbidden' - * "404": - * $ref: '#/components/responses/NotFound' + * delete: + * summary: Delete a user + * description: Logged in users can delete only themselves. Only admins can delete other users. + * tags: [Users] + * security: + * - bearerAuth: [] + * parameters: + * - in: path + * name: id + * required: true + * schema: + * type: string + * description: User id + * responses: + * "200": + * description: No content + * "401": + * $ref: '#/components/responses/Unauthorized' + * "403": + * $ref: '#/components/responses/Forbidden' + * "404": + * $ref: '#/components/responses/NotFound' */ diff --git a/yarn.lock b/yarn.lock index 633623e6..22b055dc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1653,10 +1653,10 @@ commander@2.15.1: resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f" integrity sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag== -commander@6.1.0: - version "6.1.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-6.1.0.tgz#f8d722b78103141006b66f4c7ba1e97315ba75bc" - integrity sha512-wl7PNrYWd2y5mp1OK/LhTlv8Ff4kQJQRXXAvF+uU/TPNiVJUxZLRYGj/B0y/lPGAVcSbJqH2Za/cvHmrPMC8mA== +commander@6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.0.tgz#b990bfb8ac030aedc6d11bc04d1488ffef56db75" + integrity sha512-zP4jEKbe8SHzKJYQmq8Y9gYjtO/POJLgIdKgV7B9qNmABVFVc+ctqSX6iXh4mCpJfRBOabiZ2YKPg8ciDw6C+Q== commander@^2.7.1: version "2.20.3" @@ -3998,14 +3998,6 @@ js-tokens@^4.0.0: resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== -js-yaml@3.14.0: - version "3.14.0" - resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.0.tgz#a7a34170f26a21bb162424d8adacb4113a69e482" - integrity sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A== - dependencies: - argparse "^1.0.7" - esprima "^4.0.0" - js-yaml@^3.13.1: version "3.14.1" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.1.tgz#dae812fdb3825fa306609a8717383c50c36a0537" @@ -6361,16 +6353,16 @@ supports-hyperlinks@^2.0.0: has-flag "^4.0.0" supports-color "^7.0.0" -swagger-jsdoc@4.2.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/swagger-jsdoc/-/swagger-jsdoc-4.2.0.tgz#f891d1f750e5bf6e8e9ede5e0a31bca566636180" - integrity sha512-QuEMMDddyiMQi/g5jlwtjc902xJe28n1Q9zbgqX0hBjcNybKPmrJykMElvlGtZ9CL0xk08OXNOZQUCEsk9kY0g== +swagger-jsdoc@^6.0.8: + version "6.0.8" + resolved "https://registry.yarnpkg.com/swagger-jsdoc/-/swagger-jsdoc-6.0.8.tgz#8b3f0684485ff80c83cb681c93ee4d45bb244a7a" + integrity sha512-LVI4dp1/FZ1f5A57jl4TveHDEAiHWIlqxApMJcM+oEeh5BGZ/hH1KBonU/S3p2DPrt4DivkQIFZGxUdIfmbVNg== dependencies: - commander "6.1.0" + commander "6.2.0" doctrine "3.0.0" glob "7.1.6" - js-yaml "3.14.0" swagger-parser "10.0.2" + yaml "2.0.0-1" swagger-parser@10.0.2: version "10.0.2" @@ -6384,10 +6376,10 @@ swagger-ui-dist@^3.18.1: resolved "https://registry.yarnpkg.com/swagger-ui-dist/-/swagger-ui-dist-3.38.0.tgz#fd7c6c04f2eb2dbfedd94722aa3148f3bf354cb5" integrity sha512-sselV8VY6f1BBauY9Sdmwz0jVaWTnGuHQWei7BaTpiUrLcoEUdmmK5bKefLXiwq+dx//es2S8mOvUS+tcXDsKg== -swagger-ui-express@4.1.4: - version "4.1.4" - resolved "https://registry.yarnpkg.com/swagger-ui-express/-/swagger-ui-express-4.1.4.tgz#8b814ad998b850a1cf90e71808d6d0a8a8daf742" - integrity sha512-Ea96ecpC+Iq9GUqkeD/LFR32xSs8gYqmTW1gXCuKg81c26WV6ZC2FsBSPVExQP6WkyUuz5HEiR0sEv/HCC343g== +swagger-ui-express@^4.1.6: + version "4.1.6" + resolved "https://registry.yarnpkg.com/swagger-ui-express/-/swagger-ui-express-4.1.6.tgz#682294af3d5c70f74a1fa4d6a9b503a9ee55ea82" + integrity sha512-Xs2BGGudvDBtL7RXcYtNvHsFtP1DBFPMJFRxHe5ez/VG/rzVOEjazJOOSc/kSCyxreCTKfJrII6MJlL9a6t8vw== dependencies: swagger-ui-dist "^3.18.1" @@ -7004,6 +6996,11 @@ yallist@^4.0.0: resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== +yaml@2.0.0-1: + version "2.0.0-1" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.0.0-1.tgz#8c3029b3ee2028306d5bcf396980623115ff8d18" + integrity sha512-W7h5dEhywMKenDJh2iX/LABkbFnBxasD27oyXWDS/feDsxiw0dD5ncXdYXgkvAsXIY2MpW/ZKkr9IU30DBdMNQ== + yaml@^1.10.0: version "1.10.0" resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e"