From 1619bf85c86ee1cbb2a5e8fb243ce042a06b813d Mon Sep 17 00:00:00 2001 From: tamalCodes Date: Tue, 16 Apr 2024 22:29:01 +0530 Subject: [PATCH] fix: changes for API docs --- README.md | 8 ++++---- routes/club/Club.js | 32 ++++++++++++++++++++++++++++++++ static/Status.js | 1 + 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 27c3566..379e739 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,13 @@ Milan is a hub to **connect** NGOs, Charities, and the world to **collaborate**
-C Sponsor Tamal +C Sponsor Tamal + -
Milan Readme Banner - +

@@ -32,7 +32,7 @@ Milan is a hub to **connect** NGOs, Charities, and the world to **collaborate** C C C - +


diff --git a/routes/club/Club.js b/routes/club/Club.js index 34a325c..07e03d4 100644 --- a/routes/club/Club.js +++ b/routes/club/Club.js @@ -1,7 +1,10 @@ +/* eslint-disable no-unused-vars */ const express = require("express"); const User = require("../../schema/user/UserSchema"); const { STATUSCODE, STATUSMESSAGE } = require("../../static/Status"); const router = express.Router(); +const jwt = require("jsonwebtoken"); +const UserSchema = require("../../schema/user/UserSchema"); router.get("/", async (req, res) => { try { @@ -28,4 +31,33 @@ router.get("/", async (req, res) => { } }); +router.get("/dashboard", async (req, res) => { + try { + const token = req.cookies.Token; + + if (!token) { + return res + .status(STATUSCODE.FORBIDDEN) + .json({ message: STATUSMESSAGE.FORBIDDEN }); + } + + const { User } = jwt.verify(token, process.env.JWT_SECRET); + const data = await UserSchema.findOne({ email: User.id }); + + if (!data) + return res + .status(STATUSCODE.NOT_FOUND) + .json({ message: STATUSMESSAGE.DASHBOARD_FETCH_FAILED }); + + const { password, _id, __v, ...dataWithoutSensitiveInfo } = data.toObject(); + const dashboardData = { ...dataWithoutSensitiveInfo }; + + return res.status(STATUSCODE.OK).json(dashboardData); + } catch (error) { + res + .status(STATUSCODE.INTERNAL_SERVER_ERROR) + .json({ message: STATUSMESSAGE.INTERNAL_SERVER_ERROR }); + } +}); + module.exports = router; diff --git a/static/Status.js b/static/Status.js index 838860e..96d2b56 100644 --- a/static/Status.js +++ b/static/Status.js @@ -33,6 +33,7 @@ const STATUSMESSAGE = { SIGNUP_SUCCESS: "Signed up !", SIGNUP_FAILED: "Signup failed !", USER_NOT_FOUND: "User not found !", + DASHBOARD_FETCH_FAILED: "Failed to fetch dashboard data !", USER_ALREADY_EXISTS: "User already exists, please Login !", INVALID_CREDENTIALS: "Invalid credentials !", INTERNAL_SERVER_ERROR: "Internal server error, try again later !",