Skip to content

Commit

Permalink
scretch4
Browse files Browse the repository at this point in the history
  • Loading branch information
user.name "rohit nagani committed Dec 24, 2024
1 parent c1ce756 commit 53485fc
Show file tree
Hide file tree
Showing 2,418 changed files with 373,798 additions and 1,154 deletions.
66 changes: 66 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
EXPRESS_SESSION_SECRET_OWNER = Mykrishna_nsnncijsdjej884y84939848jffnknnkjndfjfjeji884858

# ################# REQUIRED ENV VARS START #################
PORT=3000
MONGO_MEMORY_SERVER_PORT=10000 # mongodb port for e2e testing
MONGODB_URI=mongodb://localhost:27017 # `mongodb://localhost:27017` in case using local mongodb
NODE_ENV=development # changing this will avoid stack traces in the error response
EXPRESS_SESSION_SECRET=7fdOMCFRSLD9cv1k-5n3Dz5n3DmVmVHVIg9GG_OGTUkBfLNdgZAwKDNtoCJ0X0cyqaM0ogR80-zh9kx0Mkx # ok to change

ACCESS_TOKEN_SECRET=LD9cv1kBfgRHVIg9GG_OGzh9TUkcyqgZAaM0o3DmVkx08MCFRSzMocyO3UtNdDNtoCJ0X0-5nLwK7fdO # ok to change
ACCESS_TOKEN_EXPIRY=1d # 1 day. Formats: https://github.com/vercel/ms#examples
REFRESH_TOKEN_SECRET=CMdDNtowK7fX0-5D9cv0oJ008MCFRSLHVTUkcyqgZAaIg9GG_OGzh9zMocyO3UtN1kBfLRn3DmVkxdO # ok to change
REFRESH_TOKEN_EXPIRY=10d # 10 days. Formats: https://github.com/vercel/ms#examples
# CORS_ORIGIN=http://localhost # add the frontend URL (more secure)
CORS_ORIGIN=http://localhost:3000 # This must be ("*") or comma separated origins ("https://example1.com,https://example2.com,http://localhost:3000")
FREEAPI_HOST_URL=http://localhost:8080
# ################# REQUIRED ENV VARS END #################

# ----------------------------------------------------------------------------------------------------------

# ################ ENV VARS TO SEND MAILS THROUGH MAILTRAP START #################
MAILTRAP_SMTP_HOST=__mailtrap_smtp_host__
MAILTRAP_SMTP_PORT=__mailtrap_smtp_port__
MAILTRAP_SMTP_USER=__mailtrap_smtp_user_id__
MAILTRAP_SMTP_PASS=__mailtrap_smtp_user_password__
# ################ ENV VARS TO SEND MAILS THROUGH MAILTRAP END #################

# # ----------------------------------------------------------------------------------------------------------

# ################ ENV VARS TO ENABLE PAYMENT THROUGH RAZORPAY START #################
RAZORPAY_KEY_ID=__razorpay_key_id__
RAZORPAY_KEY_SECRET=__razorpay_key_secret__
# ################ ENV VARS TO ENABLE PAYMENT THROUGH RAZORPAY END #################

# # ----------------------------------------------------------------------------------------------------------

# ################ ENV VARS TO ENABLE PAYMENT THROUGH PAYPAL START #################
PAYPAL_CLIENT_ID=__paypal_client_id__
PAYPAL_SECRET=__paypal_secret__
# ################ ENV VARS TO ENABLE PAYMENT THROUGH PAYPAL END #################

# # ----------------------------------------------------------------------------------------------------------

# ################ ENV VARS TO ENABLE GOOGLE SSO LOGIN START #################
GOOGLE_CLIENT_ID=__google_client_id__
GOOGLE_CLIENT_SECRET=__google_client_secret__
GOOGLE_CALLBACK_URL=http://localhost:8080/api/v1/users/google/callback # Add this exact url in your Authorized redirect URIs in Google cloude console OAuth Client id form
# ################ ENV VARS TO ENABLE GOOGLE SSO LOGIN END #################

# # ----------------------------------------------------------------------------------------------------------

# ################ ENV VARS TO ENABLE GITHUB SSO LOGIN START #################
GITHUB_CLIENT_ID=__github_client_id__
GITHUB_CLIENT_SECRET=__github_client_secret__
GITHUB_CALLBACK_URL=http://localhost:8080/api/v1/users/github/callback # Add this exact url in your Authorization callback url in github OAuth app
# ################ ENV VARS TO ENABLE GITHUB SSO LOGIN END #################

# # ----------------------------------------------------------------------------------------------------------

# ################ ENV VARS TO REDIRECT WHEN USER SIGNS UP THROUGH ANY OF THE SSOs #################
CLIENT_SSO_REDIRECT_URL=http://localhost:3000/user/profile # Frontend url where backend should redirect when user is successfully logged in through the Google/Github SSO
# ################ ENV VARS TO REDIRECT WHEN USER SIGNS UP THROUGH ANY OF THE SSOs #################

# ################ ENV VARS TO REDIRECT WHEN USER CLICKS ON THE FORGET PASSWORD LINK SENT ON THEIR EMAIL #################
FORGOT_PASSWORD_REDIRECT_URL=http://localhost:3000/forgot-password # Frontend url where the user should be redirected when the user clicks on the reset password link sent to their email.
# ################ ENV VARS TO REDIRECT WHEN USER CLICKS ON THE FORGET PASSWORD LINK SENT ON THEIR EMAIL #################
32 changes: 32 additions & 0 deletions apis/getProducts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

const express = require('express');
const router = express.Router();
const isLoggedin = require('../middlewares/isLoggedin');
const productModel = require('../models/product-model');
const userModel = require('../models/user-model');
const AddressModel = require('../models/address-model');


// send products data on shop.jsx

router.get("/products",isLoggedin, async function (req, res) {

try {
const products = await productModel.find();
const formattedProducts = products.map((product) => ({
...product._doc, // Spread other product fields
image: product.image.toString("base64"), // Convert Buffer to base64
}));
res.json(formattedProducts);
} catch (error) {
res.status(500).json({ error: "Failed to fetch products" });
}
});



module.exports= router;




19 changes: 15 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ const express = require("express");
const app = express();
const db = require("./config/mongoose-connection")
const path= require('path');
const multer = require('multer');
const cors = require('cors');

// const multer = require('multer');
const flash = require('connect-flash');
const expressSession = require('express-session');
require('dotenv').config();//jo bhi envfile me data hei use use kar payenge like jwt keys 😊 ye dusara tarika hei pahela tarika hei devlopment environment variable set karke jo / config/monngoose-connection.js me use kiya tha
//environment ⬆ variable

const PORT = process.env.PORT || 3000;
//environment ⬆ variable
const bodyParser = require('body-parser');

app.use(cors());
app.use(bodyParser.urlencoded({ extended: true, limit: '10mb' })); // Increase limit to 10MB
app.use(bodyParser.json({ limit: '10mb' })); // Increase limit to 10MB

const PORT = process.env.PORT || 3000;

app.use(express.json());
app.use(express.urlencoded({extended:true}));
Expand All @@ -31,12 +36,18 @@ const ownersRouter= require('./routes/ownersRouter');//jisme sirf owner ke rout
const usersRouter= require('./routes/usersRouter');//jisme sirf user ke rout hoge
const productsRouter= require('./routes/productsRouter');//jisme sirf product ke rout hoge
const indexRouter = require('./routes/index');
const address = require ("./ecommerce/address.routes");
const apis = require("./apis/getProducts")

app.use("/", indexRouter)
app.use("/owners", ownersRouter)// "/owners"se raletive sari reaquest ownersRouter router par bhejo
app.use("/users", usersRouter)// "/users"se raletive sari reaquest usersRouter router par bhejo
app.use("/products", productsRouter) // "/product"se raletive sari reaquest productsRouter router par bhejo

// react apis
app.use("/api",apis)



app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
Expand Down
127 changes: 127 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* @type {{ ADMIN: "ADMIN"; USER: "USER"} as const}
*/
const UserRolesEnum = {
ADMIN: "ADMIN",
USER: "USER",
};

const AvailableUserRoles = Object.values(UserRolesEnum);

/**
* @type {{ PENDING: "PENDING"; CANCELLED: "CANCELLED"; DELIVERED: "DELIVERED" } as const}
*/
const OrderStatusEnum = {
PENDING: "PENDING",
CANCELLED: "CANCELLED",
DELIVERED: "DELIVERED",
};

const AvailableOrderStatuses = Object.values(OrderStatusEnum);

/**
* @type {{ UNKNOWN:"UNKNOWN"; RAZORPAY: "RAZORPAY"; PAYPAL: "PAYPAL"; } as const}
*/
const PaymentProviderEnum = {
UNKNOWN: "UNKNOWN",
RAZORPAY: "RAZORPAY",
PAYPAL: "PAYPAL",
};

const AvailablePaymentProviders = Object.values(PaymentProviderEnum);

/**
* @type {{ FLAT:"FLAT"; } as const}
*/
const CouponTypeEnum = {
FLAT: "FLAT",
// PERCENTAGE: "PERCENTAGE",
};

const AvailableCouponTypes = Object.values(CouponTypeEnum);

/**
* @type {{ GOOGLE: "GOOGLE"; GITHUB: "GITHUB"; EMAIL_PASSWORD: "EMAIL_PASSWORD"} as const}
*/
const UserLoginType = {
GOOGLE: "GOOGLE",
GITHUB: "GITHUB",
EMAIL_PASSWORD: "EMAIL_PASSWORD",
};

const AvailableSocialLogins = Object.values(UserLoginType);

/**
* @type {{ MOST_VIEWED: "mostViewed"; MOST_LIKED: "mostLiked"; LATEST: "latest"; OLDEST: "oldest"} as const}
*/
const YouTubeFilterEnum = {
MOST_VIEWED: "mostViewed",
MOST_LIKED: "mostLiked",
LATEST: "latest",
OLDEST: "oldest",
};

const AvailableYouTubeFilters = Object.values(YouTubeFilterEnum);

const USER_TEMPORARY_TOKEN_EXPIRY = 20 * 60 * 1000; // 20 minutes

const MAXIMUM_SUB_IMAGE_COUNT = 4;
const MAXIMUM_SOCIAL_POST_IMAGE_COUNT = 6;

const DB_NAME = "freeapi";

const paypalBaseUrl = {
sandbox: "https://api-m.sandbox.paypal.com",
};

/**
* @description set of events that we are using in chat app. more to be added as we develop the chat app
*/
const ChatEventEnum = Object.freeze({
// ? once user is ready to go
CONNECTED_EVENT: "connected",
// ? when user gets disconnected
DISCONNECT_EVENT: "disconnect",
// ? when user joins a socket room
JOIN_CHAT_EVENT: "joinChat",
// ? when participant gets removed from group, chat gets deleted or leaves a group
LEAVE_CHAT_EVENT: "leaveChat",
// ? when admin updates a group name
UPDATE_GROUP_NAME_EVENT: "updateGroupName",
// ? when new message is received
MESSAGE_RECEIVED_EVENT: "messageReceived",
// ? when there is new one on one chat, new group chat or user gets added in the group
NEW_CHAT_EVENT: "newChat",
// ? when there is an error in socket
SOCKET_ERROR_EVENT: "socketError",
// ? when participant stops typing
STOP_TYPING_EVENT: "stopTyping",
// ? when participant starts typing
TYPING_EVENT: "typing",
// ? when message is deleted
MESSAGE_DELETE_EVENT: "messageDeleted",
});

const AvailableChatEvents = Object.values(ChatEventEnum);

module.exports = {
UserRolesEnum,
AvailableUserRoles,
OrderStatusEnum,
AvailableOrderStatuses,
PaymentProviderEnum,
AvailablePaymentProviders,
CouponTypeEnum,
AvailableCouponTypes,
UserLoginType,
AvailableSocialLogins,
YouTubeFilterEnum,
AvailableYouTubeFilters,
USER_TEMPORARY_TOKEN_EXPIRY,
MAXIMUM_SUB_IMAGE_COUNT,
MAXIMUM_SOCIAL_POST_IMAGE_COUNT,
DB_NAME,
paypalBaseUrl,
ChatEventEnum,
AvailableChatEvents,
};
Loading

0 comments on commit 53485fc

Please sign in to comment.