From 93c0e27cd45535358b01c130825c483550bb4a9d Mon Sep 17 00:00:00 2001 From: TEJAS <98630752+tejaskh3@users.noreply.github.com> Date: Thu, 12 Oct 2023 14:32:03 +0530 Subject: [PATCH 1/3] feat: added oauth configration details --- docs/BackendSetup.md | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/docs/BackendSetup.md b/docs/BackendSetup.md index 04e532f..5101da9 100644 --- a/docs/BackendSetup.md +++ b/docs/BackendSetup.md @@ -29,6 +29,46 @@ directory. You must create a `.env` file similar to **[.env.example](../.env.example)** file, remember that if you are using your own database the data might vary. +## Setting up Google Client ID and Client Secret for `.env` + +To set up the Google Client ID and Client Secret for your application, follow these steps: + +1. **Project Creation:** + - Go to the [Google Developers Console](https://console.developers.google.com/apis/). + - Create a new project by clicking on the project dropdown. + + ![image](https://github.com/MilanCommunity/Milan-Backend/assets/98630752/94601cda-237d-4aed-acbf-171fd3cc3f3f) + +2. **Enable API Services:** + - Click on "Enabled API services" and select your project. + +![image](https://github.com/MilanCommunity/Milan-Backend/assets/98630752/57258b52-9f02-40e1-92a0-2ffffde8b156) + +3. **Create Credentials:** + - Navigate to the "Credentials" section. + - Click on "Create credentials" and choose "OAuth client ID." + +![image](https://github.com/MilanCommunity/Milan-Backend/assets/98630752/f11f4180-0ea1-46f3-9c4c-f8fd72cc8ee6) + +4. **Configure OAuth Client:** + - Fill out the form: + - Choose "Web application" as the application type. + - Provide your support email. + - You don't need to provide a logo for the OAuth consent screen. + +5. **Obtain Client ID and Client Secret:** + - After completing the configuration, you'll receive your Client ID and Client Secret. + + ![image](https://github.com/MilanCommunity/Milan-Backend/assets/98630752/1ce0705e-ff95-4c9c-9686-806ee08f9351) + +6. **Final Steps:** + - Update your application's `.env` file with the obtained Client ID and Client Secret. + + ```env + CLIENT_ID="your-client-id" + CLIENT_SECRET="your-client-secret" + + ### Setting up `razorpay api key` for `.env` - Head on to [Razorpay API reference](https://razorpay.com/docs/api) and Sign Up to razor pay remember you don't need to KYC. @@ -57,4 +97,4 @@ You must create a `.env` file similar to **[.env.example](../.env.example)** fil So now you have the the frontend up and running locally. Now you can start working on the issues. You can follow the below steps to get started with the frontend. -- [Setting up the frontend locally](https://github.com/MilanCommunity/Milan/blob/main/docs/FrontendSetup.md) \ No newline at end of file +- [Setting up the frontend locally](https://github.com/MilanCommunity/Milan/blob/main/docs/FrontendSetup.md) From e33c5a43b36591729ed5a7dab40bc189aaa77bf6 Mon Sep 17 00:00:00 2001 From: Mahendra Dani Date: Sun, 22 Oct 2023 14:27:51 +0530 Subject: [PATCH 2/3] fix: used status variables from utils in all routes --- routes/club/Club.js | 7 +++++-- routes/display/Display.js | 10 +++++++--- routes/payment/Payment.js | 7 +++++-- routes/shop/Products.js | 35 +++++++++++++++++++++++++---------- routes/user/Auth.js | 26 ++++++++++++++++++-------- routes/user/User.js | 30 +++++++++++++++++++----------- utils/Status.js | 6 ++++++ 7 files changed, 85 insertions(+), 36 deletions(-) diff --git a/routes/club/Club.js b/routes/club/Club.js index 613e187..8154887 100644 --- a/routes/club/Club.js +++ b/routes/club/Club.js @@ -1,12 +1,13 @@ const express = require("express"); const User = require("../../schema/user/UserSchema"); +const { STATUSCODE, STATUSMESSAGE } = require("../../utils/Status"); const router = express.Router(); router.get("/", async (req, res) => { try { if (req.query.slug) { const clubdetails = await User.findOne({ slug: req.query.slug }); - return res.status(200).json(clubdetails); + return res.status(STATUSCODE.OK).json(clubdetails); } const clubs = await User.find({ @@ -15,7 +16,9 @@ router.get("/", async (req, res) => { res.json(clubs); } catch (error) { - res.status(500).json({ message: "Internal Server Error" }); + res + .status(STATUSCODE.INTERNAL_SERVER_ERROR) + .json({ message: STATUSMESSAGE.INTERNAL_SERVER_ERROR }); } }); diff --git a/routes/display/Display.js b/routes/display/Display.js index a96ddba..853d713 100644 --- a/routes/display/Display.js +++ b/routes/display/Display.js @@ -2,7 +2,7 @@ const express = require("express"); const User = require("../../schema/user/UserSchema"); -const { STATUSCODE } = require("../../utils/Status"); +const { STATUSCODE, STATUSMESSAGE } = require("../../utils/Status"); const router = express.Router(); // Route 1 - Show all avaialble Users in the DB @@ -11,7 +11,9 @@ router.get("/users", async (req, res) => { const allusers = await User.find({}); res.status(STATUSCODE.OK).json(allusers); } catch (error) { - res.status(500).json({ message: "Internal Server Error" }); + res + .status(STATUSCODE.INTERNAL_SERVER_ERROR) + .json({ message: STATUSMESSAGE.INTERNAL_SERVER_ERROR }); } }); @@ -21,7 +23,9 @@ router.get("/clubs", async (req, res) => { const allClubs = await User.find({ usertype: "club" }); res.json(allClubs); } catch (error) { - res.status(500).json({ message: "Internal Server Error" }); + res + .status(STATUSCODE.INTERNAL_SERVER_ERROR) + .json({ message: STATUSMESSAGE.INTERNAL_SERVER_ERROR }); } }); diff --git a/routes/payment/Payment.js b/routes/payment/Payment.js index e85e608..86c58b0 100644 --- a/routes/payment/Payment.js +++ b/routes/payment/Payment.js @@ -3,6 +3,7 @@ const router = express.Router(); const shortid = require("shortid"); const Razorpay = require("razorpay"); +const { STATUSCODE, STATUSMESSAGE } = require("../../utils/Status"); const razorpay = new Razorpay({ key_id: process.env.RAZORPAY_KEY_ID, @@ -24,13 +25,15 @@ router.post("/razorpay", async (req, res) => { try { const response = await razorpay.orders.create(options); - return res.status(200).json({ + return res.status(STATUSCODE.OK).json({ id: response.id, currency: response.currency, amount: response.amount, }); } catch (error) { - res.status(500).json({ message: "Internal Server Error" }); + res + .status(STATUSCODE.INTERNAL_SERVER_ERROR) + .json({ message: STATUSMESSAGE.INTERNAL_SERVER_ERROR }); } }); diff --git a/routes/shop/Products.js b/routes/shop/Products.js index 3091223..743a133 100644 --- a/routes/shop/Products.js +++ b/routes/shop/Products.js @@ -4,6 +4,7 @@ const express = require("express"); const Products = require("../../schema/shop/ProductSchema"); const User = require("../../schema/user/UserSchema"); const router = express.Router(); +const { STATUSCODE, STATUSMESSAGE } = require("../../utils/Status"); // Route 1 - Adding Products @@ -22,7 +23,9 @@ router.post("/addproduct", async (req, res) => { const existingSlug = await Products.findOne({ productSlug }); //productSlug should be unique if (existingSlug) { - return res.status(409).json({ message: "productSlug already exists" }); + return res + .status(STATUSCODE.CONFLICT) + .json({ message: STATUSMESSAGE.PRODUCT_SLUG_ALREADY_EXISTS }); } // Create a new product object based on the schema @@ -31,10 +34,12 @@ router.post("/addproduct", async (req, res) => { // Save the new product to the database const savedProduct = await newProduct.save(); - res.status(201).json(savedProduct); // Return the saved product as a response + res.status(STATUSCODE.CREATED).json(savedProduct); // Return the saved product as a response } catch (error) { console.error("Error adding product:", error); - res.status(500).json({ message: "Failed to add product" }); + res + .status(STATUSCODE.INTERNAL_SERVER_ERROR) + .json({ message: STATUSMESSAGE.PRODUCT_ADD_FAILED }); } }); @@ -48,10 +53,12 @@ router.post("/addproduct", async (req, res) => { router.get("/allproducts", async (req, res) => { try { const allProducts = await Products.find(); - res.status(200).json(allProducts); + res.status(STATUSCODE.OK).json(allProducts); } catch (error) { console.error("Error fetching products:", error); - res.status(500).json({ message: "Failed to fetch products" }); + res + .status(STATUSCODE.INTERNAL_SERVER_ERROR) + .json({ message: STATUSMESSAGE.PRODUCT_FETCH_FAILED }); } }); @@ -69,13 +76,17 @@ router.get("/:productSlug", async (req, res) => { const product = await Products.findOne({ productSlug }); if (!product) { - return res.status(404).json({ message: "Product not found" }); + return res + .status(STATUSCODE.NOT_FOUND) + .json({ message: STATUSMESSAGE.PRODUCT_NOT_FOUND }); } - res.status(200).json(product); + res.status(STATUSCODE.OK).json(product); } catch (error) { console.error("Error fetching product:", error); - res.status(500).json({ message: "Failed to fetch product" }); + res + .status(STATUSCODE.INTERNAL_SERVER_ERROR) + .json({ message: STATUSMESSAGE.PRODUCT_FETCH_FAILED }); } }); @@ -98,10 +109,14 @@ router.post("/cart/add", async (req, res) => { if (response.modifiedCount === 1) { return res.send("Product added successfully"); } else { - res.status(404).json({ message: "User not Found" }); + res + .status(STATUSCODE.NOT_FOUND) + .json({ message: STATUSMESSAGE.USER_NOT_FOUND }); } } catch (err) { - res.status(500).json({ message: "Failed to add product to cart" }); + res + .status(STATUSCODE.INTERNAL_SERVER_ERROR) + .json({ message: STATUSMESSAGE.PRODUCT_ADD_FAILED }); console.log(err); } }); diff --git a/routes/user/Auth.js b/routes/user/Auth.js index 68aebfb..49e7424 100644 --- a/routes/user/Auth.js +++ b/routes/user/Auth.js @@ -40,18 +40,22 @@ router.post("/signin", async (req, res) => { const existingUser = await User.findOne({ email }); if (!existingUser) { - return res.status(404).json({ message: "User not found" }); + return res + .status(STATUSCODE.NOT_FOUND) + .json({ message: STATUSMESSAGE.USER_NOT_FOUND }); } const validPassword = await bcrypt.compare(password, existingUser.password); if (!validPassword) { - return res.status(401).json({ message: "Invalid Credentials" }); + return res + .status(STATUSCODE.UNAUTHORIZED) + .json({ message: STATUSMESSAGE.INVALID_CREDENTIALS }); } const payload = { User: { id: existingUser.email } }; const token = jwt.sign(payload, process.env.JWT_SECRET); res - .status(201) + .status(STATUSCODE.CREATED) .cookie("Token", token, { sameSite: "none", httpOnly: true, @@ -81,7 +85,7 @@ router.post("/signin", async (req, res) => { }) .json({ - message: "Logged you in !", + message: STATUSMESSAGE.LOGIN_SUCCESS, }); } catch (err) { res.status(STATUSCODE.INTERNAL_SERVER_ERROR).json({ message: err }); @@ -94,7 +98,9 @@ router.post("/update", async (req, res) => { const { email, oldPassword, newPassword } = req.body; const existingUser = await User.findOne({ email: email }); if (!existingUser) { - return res.status(404).json({ message: "User not found" }); + return res + .status(STATUSCODE.NOT_FOUND) + .json({ message: STATUSMESSAGE.USER_NOT_FOUND }); } // User Exists in the database const validPassword = await bcrypt.compare( @@ -103,7 +109,9 @@ router.post("/update", async (req, res) => { ); if (!validPassword) { - return res.status(401).json({ message: "Invalid Credentials" }); + return res + .status(STATUSCODE.UNAUTHORIZED) + .json({ message: STATUSMESSAGE.USER_NOT_FOUND }); } // Old Password Mathched if (newPassword.length < 5) { @@ -127,12 +135,14 @@ router.post("/update", async (req, res) => { }; await User.replaceOne({ email: email }, UserData); - res.status(201).json({ message: "Password Updated Successfully" }); + res + .status(STATUSCODE.CREATED) + .json({ message: STATUSMESSAGE.PASSWORD_UPDATE_SUCCESS }); } catch (error) { // User Password Updated res .status(STATUSCODE.INTERNAL_SERVER_ERROR) - .json({ message: "Internal Server Error" }); + .json({ message: STATUSMESSAGE.INTERNAL_SERVER_ERROR }); } }); diff --git a/routes/user/User.js b/routes/user/User.js index 30e08c3..d855eaf 100644 --- a/routes/user/User.js +++ b/routes/user/User.js @@ -3,7 +3,7 @@ const User = require("../../schema/user/UserSchema"); const router = express.Router(); const bcrypt = require("bcryptjs"); const ReportProblem = require("../../schema/user/ReportProblemSchema"); -const { STATUSCODE } = require("../../utils/Status"); +const { STATUSCODE, STATUSMESSAGE } = require("../../utils/Status"); // Route 1 - Update User details router.post("/update", async (req, res) => { @@ -11,7 +11,9 @@ router.post("/update", async (req, res) => { const { email, oldPassword, newPassword } = req.body; const existingUser = await User.findOne({ email: email }); if (!existingUser) { - return res.status(404).json({ message: "User not found" }); + return res + .status(STATUSCODE.NOT_FOUND) + .json({ message: STATUSMESSAGE.USER_NOT_FOUND }); } // User Exists in the database const validPassword = await bcrypt.compare( @@ -20,7 +22,9 @@ router.post("/update", async (req, res) => { ); if (!validPassword) { - return res.status(401).json({ message: "Invalid Credentials" }); + return res + .status(STATUSCODE.UNAUTHORIZED) + .json({ message: STATUSMESSAGE.INVALID_CREDENTIALS }); } // Old Password Mathched if (newPassword.length < 5) { @@ -44,12 +48,14 @@ router.post("/update", async (req, res) => { }; await User.replaceOne({ email: email }, UserData); - res.status(201).json({ message: "Password Updated Successfully" }); + res + .status(STATUSCODE.CREATED) + .json({ message: STATUSMESSAGE.PASSWORD_UPDATE_SUCCESS }); } catch (error) { // User Password Updated res .status(STATUSCODE.INTERNAL_SERVER_ERROR) - .json({ message: "Internal Server Error" }); + .json({ message: STATUSMESSAGE.INTERNAL_SERVER_ERROR }); } }); @@ -67,9 +73,9 @@ router.post("/report", async (req, res) => { ).getMinutes(); if (hourOfThisReport >= currentHour - 120) { - return res.status(429).json({ + return res.status(STATUSCODE.TOO_MANY_REQUESTS).json({ success: false, - message: "You have already reported a problem in the last 2 hours.", + message: STATUSMESSAGE.TOO_MANY_REQUESTS, }); } } @@ -84,11 +90,11 @@ router.post("/report", async (req, res) => { }); await ReportData.save(); - res.status(200).json({ success: true }); + res.status(STATUSCODE.OK).json({ success: true }); } catch (e) { res .status(STATUSCODE.INTERNAL_SERVER_ERROR) - .json({ message: "Internal Server Error" }); + .json({ message: STATUSMESSAGE.INTERNAL_SERVER_ERROR }); } }); @@ -96,7 +102,7 @@ router.get("/", async (req, res) => { try { if (req.query.slug) { const userdetails = await User.findOne({ slug: req.query.slug }); - return res.status(200).json(userdetails); + return res.status(STATUSCODE.OK).json(userdetails); } const users = await User.find({ @@ -105,7 +111,9 @@ router.get("/", async (req, res) => { res.json(users); } catch (error) { - res.status(500).json({ message: "Internal Server Error" }); + res + .status(STATUSCODE.INTERNAL_SERVER_ERROR) + .json({ message: STATUSMESSAGE.INTERNAL_SERVER_ERROR }); } }); diff --git a/utils/Status.js b/utils/Status.js index 7208566..fc2d29a 100644 --- a/utils/Status.js +++ b/utils/Status.js @@ -41,6 +41,12 @@ const STATUSMESSAGE = { NOT_FOUND: "Not found !", EVENT_SLUG_ALREADY_EXISTS: "Event slug already exists", CREATE_EVENT_FAILED: "Failed to create event", + PRODUCT_SLUG_ALREADY_EXISTS: "productSlug already exists", + PRODUCT_ADD_FAILED: "Failed to add product", + PRODUCT_FETCH_FAILED: "Failed to fetch products", + PRODUCT_NOT_FOUND: "Product not found", + PASSWORD_UPDATE_SUCCESS: "Password Updated Successfully", + TOO_MANY_REQUESTS: "You have already reported a problem in the last 2 hours.", }; module.exports = { STATUSCODE, STATUSMESSAGE }; From 1d9d242508c4708053ff7db84e56e7ef61ba5fb8 Mon Sep 17 00:00:00 2001 From: Tamal Das Date: Fri, 2 Feb 2024 11:17:05 +0530 Subject: [PATCH 3/3] fix: changes made to beta --- .github/workflows/production-beta.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/production-beta.yml b/.github/workflows/production-beta.yml index eb11d6c..80c9e3f 100644 --- a/.github/workflows/production-beta.yml +++ b/.github/workflows/production-beta.yml @@ -8,7 +8,7 @@ on: workflow_dispatch: push: branches: - - main + - beta jobs: Deploy-to-Production: