| @@ -1,3 +1,4 @@ | |||
| node_modules/ | |||
| loggerFiles/ | |||
| public/loggerFiles | |||
| public/loggerFiles | |||
| .idea | |||
| @@ -12,7 +12,6 @@ | |||
| "bcryptjs": "^2.4.3", | |||
| "config": "^3.3.7", | |||
| "cors": "^2.8.5", | |||
| "elmah.io.javascript": "^3.7.0", | |||
| "express": "^4.18.1", | |||
| "express-jwt": "^7.7.2", | |||
| "helmet": "^5.1.0", | |||
| @@ -994,11 +993,6 @@ | |||
| "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", | |||
| "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" | |||
| }, | |||
| "node_modules/elmah.io.javascript": { | |||
| "version": "3.7.0", | |||
| "resolved": "https://registry.npmjs.org/elmah.io.javascript/-/elmah.io.javascript-3.7.0.tgz", | |||
| "integrity": "sha512-s7yyLo8tlZPURYxsT4tS977FfEXXaMzkbxZNLVRc90v949NgdfeJYLYyYe6c5fhcQkiIPsy3TgOCErSpaJWGvw==" | |||
| }, | |||
| "node_modules/emoji-regex": { | |||
| "version": "8.0.0", | |||
| "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", | |||
| @@ -4111,11 +4105,6 @@ | |||
| "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", | |||
| "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" | |||
| }, | |||
| "elmah.io.javascript": { | |||
| "version": "3.7.0", | |||
| "resolved": "https://registry.npmjs.org/elmah.io.javascript/-/elmah.io.javascript-3.7.0.tgz", | |||
| "integrity": "sha512-s7yyLo8tlZPURYxsT4tS977FfEXXaMzkbxZNLVRc90v949NgdfeJYLYyYe6c5fhcQkiIPsy3TgOCErSpaJWGvw==" | |||
| }, | |||
| "emoji-regex": { | |||
| "version": "8.0.0", | |||
| "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", | |||
| @@ -16,7 +16,6 @@ | |||
| "bcryptjs": "^2.4.3", | |||
| "config": "^3.3.7", | |||
| "cors": "^2.8.5", | |||
| "elmah.io.javascript": "^3.7.0", | |||
| "express": "^4.18.1", | |||
| "express-jwt": "^7.7.2", | |||
| "helmet": "^5.1.0", | |||
| @@ -1,7 +0,0 @@ | |||
| module.exports = { | |||
| openapi: "3.0.3", | |||
| info: { | |||
| title: "Trampa", | |||
| description: "Trampa api" | |||
| } | |||
| } | |||
| @@ -1,41 +0,0 @@ | |||
| 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" | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,14 +0,0 @@ | |||
| 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 | |||
| } | |||
| @@ -1,34 +0,0 @@ | |||
| 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 | |||
| } | |||
| } | |||
| } | |||
| @@ -1,35 +0,0 @@ | |||
| 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" | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,27 +0,0 @@ | |||
| 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" | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,24 +0,0 @@ | |||
| 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!" | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,48 +0,0 @@ | |||
| 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", | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,30 +0,0 @@ | |||
| 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", | |||
| }, | |||
| }, | |||
| }, | |||
| }; | |||
| @@ -1,38 +0,0 @@ | |||
| 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" | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,25 +0,0 @@ | |||
| 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" | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,25 +0,0 @@ | |||
| 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: { | |||
| } | |||
| } | |||
| } | |||
| @@ -1,48 +0,0 @@ | |||
| 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", | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,8 +0,0 @@ | |||
| module.exports = { | |||
| servers: [ | |||
| { | |||
| url: "http://localhost:3000/", | |||
| description: "Local server", | |||
| }, | |||
| ], | |||
| } | |||
| @@ -1,7 +0,0 @@ | |||
| module.exports = { | |||
| tags: [ | |||
| { | |||
| name: "User" | |||
| }, | |||
| ], | |||
| } | |||
| @@ -1,20 +1,21 @@ | |||
| const winston = require('winston') | |||
| const config = require('config') | |||
| const loggerWinston = winston.createLogger({ | |||
| const logger = winston.createLogger({ | |||
| level: 'info', | |||
| format: winston.format.json(), | |||
| defaultMeta: { service: 'user-service' }, | |||
| transports: [ | |||
| new winston.transports.File({ filename: '../public/loggerFiles/error.log', level: 'error' }), | |||
| new winston.transports.File({ filename: '../public/loggerFiles/all.log', level: 'silly' }), | |||
| new winston.transports.Console({level: 'silly'}), | |||
| ], | |||
| }); | |||
| if (config.util.getEnv('NODE_ENV') !== 'production') { | |||
| loggerWinston.add(new winston.transports.Console({ | |||
| logger.add(new winston.transports.Console({ | |||
| format: winston.format.simple(), | |||
| })); | |||
| } | |||
| module.exports = loggerWinston | |||
| module.exports = logger | |||
| @@ -1,10 +0,0 @@ | |||
| // const Elmahio = require("elmah.io.javascript") | |||
| // | |||
| // // TODO: da li ovo treba u configu (appsettings.json) da bude ili moze ovde hardkodirano | |||
| // const loggerElmah = new Elmahio({ | |||
| // apiKey: 'API_KEY', | |||
| // logId: 'LOG_ID', | |||
| // application: 'diligent-node-api' | |||
| // }) | |||
| // | |||
| // module.exports = loggerElmah | |||
| @@ -1,14 +1,11 @@ | |||
| //const loggerElmah = require('../logging/loggerElmah') | |||
| const loggerWinston = require('../logging/loggerWinston') | |||
| const logger = require('../logging/logger') | |||
| const config = require('config') | |||
| const errorLogger = (err, req, res, next) => { | |||
| console.error(err) | |||
| //console.error(err) | |||
| if (config.util.getEnv('NODE_ENV') === 'development') | |||
| loggerWinston.error(err) | |||
| // else | |||
| // loggerElmah.error('There has been an error', err) | |||
| logger.error(err) | |||
| next(err) | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| const logger = require("../logging/loggerWinston") | |||
| const logger = require("../logging/logger") | |||
| const requestLogging = async (req, res, next) => { | |||
| res.header("Content-Type", 'application/json'); | |||
| @@ -3,8 +3,8 @@ const express = require('express') | |||
| const app = express() | |||
| const port = process.env.NODE_ENV === 'production' ? 80 : 3001 | |||
| require('./database/mongoose') | |||
| 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 requestLogging = require('./middleware/requestLogging.js') | |||
| const cors = require('cors') //Cross-origin resource sharing | |||
| @@ -0,0 +1,351 @@ | |||
| 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" | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||