first commit
This commit is contained in:
parent
b2ec37a50b
commit
6c3f7b7db9
16
.env
Normal file
16
.env
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
# DB_URL ="mongodb://localhost:27017/Atp-project"
|
||||
DB_URL="mongodb+srv://chatgptairport:FoluznYecXJeEcx8@cluster0.iih5dsg.mongodb.net/?retryWrites=true&w=majority"
|
||||
PORT = 5000
|
||||
JWT_SECRET = jdvnvjwrniwj4562jn67hvgtdr@65drfdgfc35r578;
|
||||
|
||||
|
||||
// chatGptAirport cloudinary credential
|
||||
CLOUDINARY_NAME = "dfwcshsrb"
|
||||
CLOUDINARY_API_KEY = "729179972558718"
|
||||
CLOUDINARY_API_SECRET = "XWtPK6iHcWABNTh2qegrN5Df9OU"
|
||||
|
||||
SEND_EMAIL_FROM="chatgpt.airport@gmail.com"
|
||||
|
||||
# AnyTimePrasad(ATM)
|
||||
SENDGRID_API_KEY="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"
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
node_modules
|
||||
.env
|
||||
|
||||
tmp
|
||||
tmp/
|
@ -21,6 +21,10 @@ import {
|
||||
import { authorizeRoles, isAuthenticatedUser, isFranchiAuthenticated } from "../../middlewares/auth.js";
|
||||
import { FranchiseeVarificationFromAdmin } from "./Franchisee_controller.js";
|
||||
import { FranchiseePriceLevelProduct } from "./Franchisee_controller.js";
|
||||
import { createOrder } from "./Franchisee_controller.js";
|
||||
import { EditOrderBeforePayment } from "./Franchisee_controller.js";
|
||||
import { getSingleOrder } from "./Franchisee_controller.js";
|
||||
import { getAllOrder } from "./Franchisee_controller.js";
|
||||
|
||||
router.get("/", getAllFranchisees);
|
||||
router.get("/withpopulate", isAuthenticatedUser, getAllFranchiseesPopulated);
|
||||
@ -52,6 +56,12 @@ router.patch("/edit/self", isFranchiAuthenticated, EditFranchiseeProfile);
|
||||
router.route("/password/update").put(isFranchiAuthenticated, franchiseeUpdatePassword);
|
||||
//fetch product franchisee Wise
|
||||
router.route("/product/price_level").get(isFranchiAuthenticated, FranchiseePriceLevelProduct);
|
||||
//product order
|
||||
router.route("/order/create").post(isFranchiAuthenticated, createOrder)
|
||||
router.route("/order/getAll").get(isFranchiAuthenticated, getAllOrder)
|
||||
router.route("/order/getOne/:id").get(isFranchiAuthenticated, getSingleOrder)
|
||||
router.route("/order/edit/:id").put(isFranchiAuthenticated, EditOrderBeforePayment)
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { Franchisee } from "./FranchiseeModel.js";
|
||||
import sendEmail from "../../Utils/sendEmail.js"
|
||||
import cloudinary from "../../Utils/cloudinary.js";
|
||||
import { Order } from '../Orders/orderModel.js'
|
||||
import fs from "fs";
|
||||
import bcrypt from "bcryptjs"
|
||||
import password from 'secure-random-password'
|
||||
|
||||
import mongoose from "mongoose";
|
||||
import { generate } from "generate-password";
|
||||
import { Product } from "../Products/ProductModel.js";
|
||||
|
||||
const addFranchisee = async (req, res) => {
|
||||
@ -401,8 +401,9 @@ export const franchiseeForgotPassword = async (req, res, next) => {
|
||||
return res.status(500).json({ message: error?.message || "Something went wrong!" });
|
||||
}
|
||||
}
|
||||
|
||||
//edit franchi profile self
|
||||
export const EditFranchiseeProfile = async (req, res, next) => {
|
||||
export const EditFranchiseeProfile = async (req, res) => {
|
||||
const image_file = req?.files?.image;
|
||||
try {
|
||||
const FranchiseeWithURL = await Franchisee.findOne({
|
||||
@ -497,15 +498,16 @@ export const FranchiseeVarificationFromAdmin = async (req, res) => {
|
||||
return res.status(500).json({ message: err.message ? err.message : "Something went wrong." });
|
||||
}
|
||||
};
|
||||
//filter franchisee wise product
|
||||
|
||||
//filter franchisee wise product
|
||||
export const FranchiseePriceLevelProduct = async (req, res) => {
|
||||
|
||||
try {
|
||||
const getFranchisee = await Franchisee.findById(req.franchi._id);
|
||||
// console.log(getFranchisee.price_Lable)
|
||||
if (getFranchisee?.price_Lable) {
|
||||
const getFranchiseeProduct = await Product.find().select(`${getFranchisee.price_Lable}`);
|
||||
const getFranchiseeProduct = await Product.find().select(` name ${getFranchisee.price_Lable} ${getFranchisee.price_Lable}_With_Tax taxId description image
|
||||
createdAt updatedAt`);
|
||||
|
||||
|
||||
|
||||
@ -522,6 +524,177 @@ export const FranchiseePriceLevelProduct = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
//franchisee order
|
||||
export const createOrder = async (req, res) => {
|
||||
try {
|
||||
if (!req?.franchi) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
let isUnique = false;
|
||||
let order_id = generate({
|
||||
length: 9,
|
||||
numbers: true,
|
||||
lowercase: false,
|
||||
uppercase: false,
|
||||
});
|
||||
|
||||
while (!isUnique) {
|
||||
const unqOrder = await Order.findOne({ order_id });
|
||||
if (!unqOrder) {
|
||||
isUnique = true;
|
||||
} else {
|
||||
order_id = generate({
|
||||
length: 9,
|
||||
numbers: true,
|
||||
lowercase: false,
|
||||
uppercase: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
req.body.user = req?.franchi?._id
|
||||
req.body.order_id = order_id
|
||||
const order = await Order.create(req.body);
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
order,
|
||||
message: 'order Created',
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : 'Something went Wrong',
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const getAllOrder = async (req, res) => {
|
||||
try {
|
||||
if (!req?.franchi) return res.status(400).json({ message: "please login first !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
|
||||
const order = await Order.find({ user: req?.franchi?._id }).populate({
|
||||
path: "user",
|
||||
select: "name -_id",
|
||||
}).sort({ createdAt: -1 });
|
||||
if (order) {
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
order,
|
||||
message: 'All Order Fetched',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : 'Something went Wrong',
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
export const getSingleOrder = async (req, res) => {
|
||||
try {
|
||||
if (!req?.franchi) return res.status(400).json({ message: "please login first !" });
|
||||
// console.log(req?.user)
|
||||
if (!req.params.id) return res.status(400).json({ message: "please Provide Order Id" });
|
||||
|
||||
|
||||
|
||||
const order = await Order.findById(req.params.id).populate({
|
||||
path: "user",
|
||||
select: "name -_id",
|
||||
|
||||
|
||||
}).populate({
|
||||
path: "shippingInfo",
|
||||
|
||||
populate: {
|
||||
path: "Franchisee",
|
||||
select: "banner price_Lable ",
|
||||
},
|
||||
}).sort({ createdAt: -1 });
|
||||
if (order) {
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
order,
|
||||
message: ' Order Fetched',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : 'Something went Wrong',
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const EditOrderBeforePayment = async (req, res) => {
|
||||
try {
|
||||
if (!req?.franchi) return res.status(400).json({ message: "please login first !" });
|
||||
// console.log(req?.user)
|
||||
if (!req.params.id) return res.status(400).json({ message: "please Provide Order Id" });
|
||||
|
||||
|
||||
|
||||
const order = await Order.findById(req.params.id)
|
||||
if (order) {
|
||||
if (order.isPaid === false) {
|
||||
|
||||
|
||||
|
||||
if (order.user.toString() === req?.franchi._id.toString()) {
|
||||
req.body.user = req?.franchi._id
|
||||
|
||||
const ModifyOrder = await Order.findByIdAndUpdate(req.params.id, req.body,
|
||||
|
||||
{
|
||||
new: true,
|
||||
runValidators: true,
|
||||
useFindAndModify: false,
|
||||
}
|
||||
|
||||
);
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
order: ModifyOrder,
|
||||
message: ' Order Updated',
|
||||
});
|
||||
}
|
||||
else {
|
||||
return res.status(400).json({ message: 'You not created This So You Can not Edit this Order !! ' })
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
return res.status(400).json({ message: 'order can not Edited Because Payment Done !! ' })
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : 'Something went Wrong',
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export {
|
||||
addFranchisee,
|
||||
getAllFranchisees,
|
||||
|
Loading…
Reference in New Issue
Block a user