From 8ec8f79d8385cee1c9369518748f178b66a5b2f6 Mon Sep 17 00:00:00 2001 From: kunalchhabra37 Date: Tue, 5 Jul 2022 22:06:39 +0530 Subject: [PATCH] Added Logs Middleware --- apiRoutes.json | 3 +++ controllers/logController.js | 6 ++++++ index.js | 3 ++- routes/api.logs.js | 7 +++++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 controllers/logController.js create mode 100644 routes/api.logs.js diff --git a/apiRoutes.json b/apiRoutes.json index 910f274..058b722 100644 --- a/apiRoutes.json +++ b/apiRoutes.json @@ -10,6 +10,9 @@ "status": ["active", "inactive", "true","false"], "role" : "string" } + }, + "/api/logs":{ + "description":"Get all logs" } }, "POST": { diff --git a/controllers/logController.js b/controllers/logController.js new file mode 100644 index 0000000..15114c0 --- /dev/null +++ b/controllers/logController.js @@ -0,0 +1,6 @@ +const Logs = require('../models/logs'); + +exports.getLogs = async (req, res) => { + let logs = await Logs.find() + res.json(logs) +} \ No newline at end of file diff --git a/index.js b/index.js index 153adc4..1d6ff22 100644 --- a/index.js +++ b/index.js @@ -12,13 +12,14 @@ const app = express(); // Body Parser app.use(express.json()); app.use(express.urlencoded({extended: false})); - +// Middleware to log requests app.use(logger); // Home Route app.get('/', (req, res) => res.json(jsonAPiRoutes)); // API Routes app.use('/api/employees', require('./routes/api.employee')) +app.use('/api/logs', require('./routes/api.logs')) // ENV const dbConn = `mongodb+srv://${process.env.MONGO_DB_USERNAME}:${process.env.MONGO_DB_PASS}@${process.env.MONGO_DB_CLUSTER}.hvghisd.mongodb.net/${process.env.MONGO_DB_DB}` const PORT = process.env.PORT || 5000; diff --git a/routes/api.logs.js b/routes/api.logs.js new file mode 100644 index 0000000..c1996e3 --- /dev/null +++ b/routes/api.logs.js @@ -0,0 +1,7 @@ +const express = require('express') +const router = express.Router() +const logController = require('../controllers/logController') + +router.get('/', logController.getLogs) + +module.exports = router; \ No newline at end of file