| module.exports = { | |||||
| openapi: "3.0.3", | |||||
| info: { | |||||
| title: "Trampa", | |||||
| description: "Trampa api" | |||||
| } | |||||
| } |
| module.exports = { | |||||
| components: { | |||||
| schemas: { | |||||
| id: { | |||||
| type: "string", | |||||
| description: "An id of a user" | |||||
| }, | |||||
| User: { | |||||
| type: "object", | |||||
| properties: { | |||||
| name: { | |||||
| type: "string" | |||||
| }, | |||||
| email: { | |||||
| type: "string" | |||||
| }, | |||||
| password: { | |||||
| type: "string" | |||||
| }, | |||||
| tokens: { | |||||
| type: "array", | |||||
| items: { | |||||
| type: "string" | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| Token: { | |||||
| type: "object", | |||||
| properties: { | |||||
| token: { | |||||
| type: "string" | |||||
| }, | |||||
| userId: { | |||||
| type: "string" | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } |
| const basicInfo = require('./basicInfo'); | |||||
| const servers = require('./servers'); | |||||
| const components = require('./components'); | |||||
| const tags = require('./tags'); | |||||
| const routesDesc = require('./routesDesc'); | |||||
| module.exports = { | |||||
| ...basicInfo, | |||||
| ...servers, | |||||
| ...components, | |||||
| ...tags, | |||||
| ...routesDesc | |||||
| } |
| const getUser = require('./user/getUserDesc'); | |||||
| const getUsers = require('./user/getUsersDesc'); | |||||
| const createUser = require('./user/createUserDesc'); | |||||
| const updateUser = require('./user/updateUserDesc'); | |||||
| const updateUserContacts = require('./user/updateUserContactsDesc'); | |||||
| const deleteUserDesc = require('./user/deleteUserDesc'); | |||||
| const loginUserDesc = require('./token/loginUserDesc'); | |||||
| const logoutDesc = require('./token/logoutDesc'); | |||||
| const refreshTokenDesc = require('./token/refreshTokenDesc'); | |||||
| module.exports = { | |||||
| paths: { | |||||
| '/users': { | |||||
| ...getUsers, | |||||
| ...createUser | |||||
| }, | |||||
| '/users/{id}': { | |||||
| ...getUser, | |||||
| ...updateUser, | |||||
| ...updateUserContacts, | |||||
| ...deleteUserDesc | |||||
| }, | |||||
| '/auth/token': { | |||||
| ...loginUserDesc | |||||
| }, | |||||
| '/auth/logout': { | |||||
| ...logoutDesc | |||||
| }, | |||||
| '/auth/refresh': { | |||||
| ...refreshTokenDesc | |||||
| } | |||||
| } | |||||
| } |
| module.exports = { | |||||
| post: { | |||||
| tags: ["Token"], | |||||
| description: "Log in user", | |||||
| parameters: [], | |||||
| requestBody: { | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| type: "object", | |||||
| properties: { | |||||
| email: { | |||||
| type: "string" | |||||
| }, | |||||
| password: { | |||||
| type: "string" | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| responses: { | |||||
| 201: { | |||||
| description: "User logged in successfully!" | |||||
| }, | |||||
| 400: { | |||||
| description: "Wrong credentials!" | |||||
| }, | |||||
| 500: { | |||||
| description: "Internal server error" | |||||
| } | |||||
| } | |||||
| } | |||||
| } |
| module.exports = { | |||||
| post: { | |||||
| tags: ["Token"], | |||||
| description: "Log out user", | |||||
| parameters: [], | |||||
| requestBody: { | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| $ref: "#/components/schemas/Token" | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| responses: { | |||||
| 201: { | |||||
| description: "User logged out successfully" | |||||
| }, | |||||
| 404: { | |||||
| description: "No user has the token provided!" | |||||
| }, | |||||
| 500: { | |||||
| description: "Internal server error" | |||||
| } | |||||
| } | |||||
| } | |||||
| } |
| module.exports = { | |||||
| post: { | |||||
| tags: ["Token"], | |||||
| description: "Log out user", | |||||
| parameters: [], | |||||
| requestBody: { | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| $ref: "#/components/schemas/Token" | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| responses: { | |||||
| 201: { | |||||
| description: "User refreshed successfully" | |||||
| }, | |||||
| 404: { | |||||
| description: "Token not valid!" | |||||
| } | |||||
| } | |||||
| } | |||||
| } |
| module.exports = { | |||||
| post: { | |||||
| tags: ["User"], | |||||
| description: "Create user", | |||||
| parameters: [], | |||||
| requestBody: { | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| type: "object", | |||||
| properties: { | |||||
| name: { | |||||
| type: "string" | |||||
| }, | |||||
| email: { | |||||
| type: "string" | |||||
| }, | |||||
| password: { | |||||
| type: "string" | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| responses: { | |||||
| 201: { | |||||
| description: "User created successfully", | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| $ref: "#/components/schemas/User" | |||||
| }, | |||||
| }, | |||||
| }, | |||||
| }, | |||||
| 400: { | |||||
| description: "Object cant be empty", | |||||
| }, | |||||
| 401: { | |||||
| description: "Invalid input parameters", | |||||
| }, | |||||
| 500: { | |||||
| description: "Internal server error", | |||||
| } | |||||
| } | |||||
| } | |||||
| } |
| module.exports = { | |||||
| delete: { | |||||
| tags: ["User"], | |||||
| description: "Delete user", | |||||
| parameters: [ | |||||
| { | |||||
| name: "id", | |||||
| in: "path", | |||||
| schema: { | |||||
| $ref: "#/components/schemas/id", | |||||
| }, | |||||
| required: true, | |||||
| }, | |||||
| ], | |||||
| responses: { | |||||
| 204: { | |||||
| description: "User deleted successfully", | |||||
| }, | |||||
| 400: { | |||||
| description: "You need to provide valid Id'", | |||||
| }, | |||||
| 404: { | |||||
| description: "User not found", | |||||
| }, | |||||
| 500: { | |||||
| description: "Internal server error", | |||||
| }, | |||||
| }, | |||||
| }, | |||||
| }; |
| module.exports = { | |||||
| get: { | |||||
| tags: ["User"], | |||||
| description: "Get user by id", | |||||
| parameters: [ | |||||
| { | |||||
| name: "id", | |||||
| in: "path", | |||||
| schema: { | |||||
| $ref: "#/components/schemas/id", | |||||
| }, | |||||
| required: true, | |||||
| description: "A single user id", | |||||
| } | |||||
| ], | |||||
| responses: { | |||||
| 200: { | |||||
| description: "Success", | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| $ref: "#/components/schemas/User", | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| 400: { | |||||
| description: "Bad request" | |||||
| }, | |||||
| 404: { | |||||
| description: "User with specified id does not exist" | |||||
| }, | |||||
| 500: { | |||||
| description: "Internal server error" | |||||
| } | |||||
| } | |||||
| } | |||||
| } |
| module.exports = { | |||||
| get: { | |||||
| tags: ["User"], | |||||
| description: "Get all users", | |||||
| parameters: [], | |||||
| responses: { | |||||
| 200: { | |||||
| description: "Success", | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| $ref: "#/components/schemas/User", | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| 200: { | |||||
| description: "Users returned successfully" | |||||
| }, | |||||
| 500: { | |||||
| description: "Internal server error" | |||||
| } | |||||
| } | |||||
| } | |||||
| } |
| module.exports = { | |||||
| patch: { | |||||
| tags: ["User"], | |||||
| description: "Update user", | |||||
| parameters: [ | |||||
| { | |||||
| name: "id", | |||||
| in: "path", | |||||
| // schema: { | |||||
| // $ref: "#/components/schemas/id", // data model of the param | |||||
| // }, | |||||
| required: true, | |||||
| description: "A single user id", | |||||
| } | |||||
| ], | |||||
| requestBody: { | |||||
| content: { | |||||
| } | |||||
| }, | |||||
| responses: { | |||||
| } | |||||
| } | |||||
| } |
| module.exports = { | |||||
| put: { | |||||
| tags: ["User"], | |||||
| description: "Update user", | |||||
| parameters: [ | |||||
| { | |||||
| name: "id", | |||||
| in: "path", | |||||
| schema: { | |||||
| $ref: "#/components/schemas/id", // data model of the param | |||||
| }, | |||||
| required: true, | |||||
| description: "A single user id", | |||||
| } | |||||
| ], | |||||
| requestBody: { | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| type: "object", | |||||
| properties: { | |||||
| name: { | |||||
| type: "string" | |||||
| }, | |||||
| email: { | |||||
| type: "string" | |||||
| }, | |||||
| password: { | |||||
| type: "string" | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| responses: { | |||||
| 200: { | |||||
| description: "User updated successfully", | |||||
| }, | |||||
| 400: { | |||||
| description: "Invalid input parameters", | |||||
| }, | |||||
| 500: { | |||||
| description: "Server error", | |||||
| } | |||||
| } | |||||
| } | |||||
| } |
| module.exports = { | |||||
| servers: [ | |||||
| { | |||||
| url: "http://localhost:3000/", | |||||
| description: "Local server", | |||||
| }, | |||||
| ], | |||||
| } |
| module.exports = { | |||||
| tags: [ | |||||
| { | |||||
| name: "User" | |||||
| }, | |||||
| ], | |||||
| } |
| require('./database/mongoose') | require('./database/mongoose') | ||||
| const userRouter = require('./routes/user') | const userRouter = require('./routes/user') | ||||
| const tokenRouter = require('./routes/token') | const tokenRouter = require('./routes/token') | ||||
| const docs = require('./documentation'); | |||||
| const swaggerUI = require("swagger-ui-express") | |||||
| const docs = require('./swagger.js'); | |||||
| const swaggerUI = require('swagger-ui-express') | |||||
| const { errorLogger, errorResponder } = require('./middleware/errorHandling.js') | const { errorLogger, errorResponder } = require('./middleware/errorHandling.js') | ||||
| const requestLogging = require('./middleware/requestLogging.js') | const requestLogging = require('./middleware/requestLogging.js') | ||||
| const cors = require('cors') //Cross-origin resource sharing | const cors = require('cors') //Cross-origin resource sharing |
| module.exports = { | |||||
| servers: [ | |||||
| { | |||||
| url: "http://localhost:3001/", | |||||
| description: "Local server", | |||||
| }, | |||||
| ], | |||||
| tags: [ | |||||
| { | |||||
| name: "User" | |||||
| }, | |||||
| ], | |||||
| openapi: "3.0.3", | |||||
| info: { | |||||
| title: "Trampa", | |||||
| description: "Trampa api" | |||||
| }, | |||||
| paths: { | |||||
| '/users': { | |||||
| get: { | |||||
| tags: ["User"], | |||||
| description: "Get all users", | |||||
| parameters: [], | |||||
| responses: { | |||||
| 200: { | |||||
| description: "Success", | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| $ref: "#/components/schemas/User", | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| 200: { | |||||
| description: "Users returned successfully" | |||||
| }, | |||||
| 500: { | |||||
| description: "Internal server error" | |||||
| } | |||||
| } | |||||
| }, | |||||
| post: { | |||||
| tags: ["User"], | |||||
| description: "Create user", | |||||
| parameters: [], | |||||
| requestBody: { | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| type: "object", | |||||
| properties: { | |||||
| name: { | |||||
| type: "string" | |||||
| }, | |||||
| email: { | |||||
| type: "string" | |||||
| }, | |||||
| password: { | |||||
| type: "string" | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| responses: { | |||||
| 201: { | |||||
| description: "User created successfully", | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| $ref: "#/components/schemas/User" | |||||
| }, | |||||
| }, | |||||
| }, | |||||
| }, | |||||
| 400: { | |||||
| description: "Object cant be empty", | |||||
| }, | |||||
| 401: { | |||||
| description: "Invalid input parameters", | |||||
| }, | |||||
| 500: { | |||||
| description: "Internal server error", | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| '/users/{id}': { | |||||
| get: { | |||||
| tags: ["User"], | |||||
| description: "Get user by id", | |||||
| parameters: [ | |||||
| { | |||||
| name: "id", | |||||
| in: "path", | |||||
| schema: { | |||||
| $ref: "#/components/schemas/id", | |||||
| }, | |||||
| required: true, | |||||
| description: "A single user id", | |||||
| } | |||||
| ], | |||||
| responses: { | |||||
| 200: { | |||||
| description: "Success", | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| $ref: "#/components/schemas/User", | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| 400: { | |||||
| description: "Bad request" | |||||
| }, | |||||
| 404: { | |||||
| description: "User with specified id does not exist" | |||||
| }, | |||||
| 500: { | |||||
| description: "Internal server error" | |||||
| } | |||||
| } | |||||
| }, | |||||
| put: { | |||||
| tags: ["User"], | |||||
| description: "Update user", | |||||
| parameters: [ | |||||
| { | |||||
| name: "id", | |||||
| in: "path", | |||||
| schema: { | |||||
| $ref: "#/components/schemas/id", // data model of the param | |||||
| }, | |||||
| required: true, | |||||
| description: "A single user id", | |||||
| } | |||||
| ], | |||||
| requestBody: { | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| type: "object", | |||||
| properties: { | |||||
| name: { | |||||
| type: "string" | |||||
| }, | |||||
| email: { | |||||
| type: "string" | |||||
| }, | |||||
| password: { | |||||
| type: "string" | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| responses: { | |||||
| 200: { | |||||
| description: "User updated successfully", | |||||
| }, | |||||
| 400: { | |||||
| description: "Invalid input parameters", | |||||
| }, | |||||
| 500: { | |||||
| description: "Server error", | |||||
| } | |||||
| } | |||||
| }, | |||||
| patch: { | |||||
| tags: ["User"], | |||||
| description: "Update user", | |||||
| parameters: [ | |||||
| { | |||||
| name: "id", | |||||
| in: "path", | |||||
| // schema: { | |||||
| // $ref: "#/components/schemas/id", // data model of the param | |||||
| // }, | |||||
| required: true, | |||||
| description: "A single user id", | |||||
| } | |||||
| ], | |||||
| requestBody: { | |||||
| content: { | |||||
| } | |||||
| }, | |||||
| responses: { | |||||
| } | |||||
| }, | |||||
| delete: { | |||||
| tags: ["User"], | |||||
| description: "Delete user", | |||||
| parameters: [ | |||||
| { | |||||
| name: "id", | |||||
| in: "path", | |||||
| schema: { | |||||
| $ref: "#/components/schemas/id", | |||||
| }, | |||||
| required: true, | |||||
| }, | |||||
| ], | |||||
| responses: { | |||||
| 204: { | |||||
| description: "User deleted successfully", | |||||
| }, | |||||
| 400: { | |||||
| description: "You need to provide valid Id'", | |||||
| }, | |||||
| 404: { | |||||
| description: "User not found", | |||||
| }, | |||||
| 500: { | |||||
| description: "Internal server error", | |||||
| }, | |||||
| }, | |||||
| } | |||||
| }, | |||||
| '/auth/token': { | |||||
| post: { | |||||
| tags: ["Token"], | |||||
| description: "Log in user", | |||||
| parameters: [], | |||||
| requestBody: { | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| type: "object", | |||||
| properties: { | |||||
| email: { | |||||
| type: "string" | |||||
| }, | |||||
| password: { | |||||
| type: "string" | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| responses: { | |||||
| 201: { | |||||
| description: "User logged in successfully!" | |||||
| }, | |||||
| 400: { | |||||
| description: "Wrong credentials!" | |||||
| }, | |||||
| 500: { | |||||
| description: "Internal server error" | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| '/auth/logout': { | |||||
| post: { | |||||
| tags: ["Token"], | |||||
| description: "Log out user", | |||||
| parameters: [], | |||||
| requestBody: { | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| $ref: "#/components/schemas/Token" | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| responses: { | |||||
| 201: { | |||||
| description: "User logged out successfully" | |||||
| }, | |||||
| 404: { | |||||
| description: "No user has the token provided!" | |||||
| }, | |||||
| 500: { | |||||
| description: "Internal server error" | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| '/auth/refresh': { | |||||
| post: { | |||||
| tags: ["Token"], | |||||
| description: "Log out user", | |||||
| parameters: [], | |||||
| requestBody: { | |||||
| content: { | |||||
| "application/json": { | |||||
| schema: { | |||||
| $ref: "#/components/schemas/Token" | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| responses: { | |||||
| 201: { | |||||
| description: "User refreshed successfully" | |||||
| }, | |||||
| 404: { | |||||
| description: "Token not valid!" | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| components: { | |||||
| schemas: { | |||||
| id: { | |||||
| type: "string", | |||||
| description: "An id of a user" | |||||
| }, | |||||
| User: { | |||||
| type: "object", | |||||
| properties: { | |||||
| name: { | |||||
| type: "string" | |||||
| }, | |||||
| email: { | |||||
| type: "string" | |||||
| }, | |||||
| password: { | |||||
| type: "string" | |||||
| }, | |||||
| tokens: { | |||||
| type: "array", | |||||
| items: { | |||||
| type: "string" | |||||
| } | |||||
| } | |||||
| } | |||||
| }, | |||||
| Token: { | |||||
| type: "object", | |||||
| properties: { | |||||
| token: { | |||||
| type: "string" | |||||
| }, | |||||
| userId: { | |||||
| type: "string" | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } |