first commit
This commit is contained in:
parent
a5bee589a2
commit
f1c90c9d3e
21
.env
21
.env
@ -1,16 +1,17 @@
|
||||
|
||||
# DB_URL ="mongodb://localhost:27017/Atp-project"
|
||||
DB_URL="mongodb+srv://chatgptairport:FoluznYecXJeEcx8@cluster0.iih5dsg.mongodb.net/?retryWrites=true&w=majority"
|
||||
|
||||
DB_URL="mongodb+srv://projectjatinmor:fTXdYGKiG9EyXtii@cluster0.baojdkn.mongodb.net/?retryWrites=true&w=majority"
|
||||
|
||||
PORT = 5000
|
||||
JWT_SECRET = jdvnvjwrniwj4562jn67hvgtdr@65drfdgfc35r578;
|
||||
JWT_SECRET = jdvnvjwrniwj4562jn6@1xsbfeh@wre4Njdf;
|
||||
|
||||
|
||||
// chatGptAirport cloudinary credential
|
||||
CLOUDINARY_NAME = "dfwcshsrb"
|
||||
CLOUDINARY_API_KEY = "729179972558718"
|
||||
CLOUDINARY_API_SECRET = "XWtPK6iHcWABNTh2qegrN5Df9OU"
|
||||
// Jatin Mor cloudinary credential
|
||||
CLOUDINARY_NAME = "dg8dcfqp7"
|
||||
CLOUDINARY_API_KEY = "458619733688194"
|
||||
CLOUDINARY_API_SECRET = "fW3PekVZn_BOUX9GkzxyvOZZVs4"
|
||||
|
||||
SEND_EMAIL_FROM="chatgpt.airport@gmail.com"
|
||||
SEND_EMAIL_FROM="project.jatinmor@gmail.com"
|
||||
|
||||
# chatGpt.Airport
|
||||
SENDGRID_API_KEY="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"
|
||||
# Jatin Mor
|
||||
SENDGRID_API_KEY="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"
|
8
app.js
8
app.js
@ -1,6 +1,6 @@
|
||||
|
||||
import dotenv from "dotenv";
|
||||
import express from 'express';
|
||||
import express from 'express'
|
||||
const app = express();
|
||||
import bodyParser from "body-parser";
|
||||
import fileUpload from "express-fileupload"// important pkg for file upload
|
||||
@ -23,10 +23,10 @@ app.use(fileUpload({
|
||||
//auth
|
||||
import user from "./resources/user/userRoute.js"
|
||||
import ProductRouter from "./resources/Products/ProductRoute.js";
|
||||
import orderRoute from './resources/Orders/orderRoute.js'
|
||||
import orderRoute from './resources/Orders/orderRoute.js';
|
||||
import DepartureRouter from "./resources/Departure/DepartureRoute.js";
|
||||
import InformationRoute from "./resources/Informations/InformationRoute.js";
|
||||
import ComplaintRoute from "./resources/Complaints/ComplaintRoute.js";
|
||||
import Testimonial from "./resources/Testimonials/TestimonialRoute.js";
|
||||
import ContactRequest from "./resources/ContactRequests/ContactRequestRoute.js"
|
||||
|
||||
import StateRouter from "./resources/setting/state/state_routes.js";
|
||||
@ -45,7 +45,7 @@ app.use("/api/information/", InformationRoute);
|
||||
//Contact Requests
|
||||
app.use("/api/contact/request/", ContactRequest);
|
||||
//Complaints
|
||||
app.use("/api/complaint/", ComplaintRoute);
|
||||
app.use("/api/testimonial/", Testimonial);
|
||||
//state
|
||||
app.use("/api/state", StateRouter);
|
||||
//city
|
||||
|
@ -1,6 +1,5 @@
|
||||
import mongoose from "mongoose";
|
||||
//require("dotenv").config();
|
||||
|
||||
const connectDatabase = () => {
|
||||
mongoose
|
||||
.connect(process.env.DB_URL, {
|
||||
@ -9,6 +8,8 @@ const connectDatabase = () => {
|
||||
|
||||
}).then((data) => {
|
||||
console.log(`Mongodb connected with server: ${data.connection.host}`);
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
};
|
||||
export default connectDatabase;
|
||||
|
@ -1,53 +0,0 @@
|
||||
|
||||
import { Complaint } from "./ComplaintModel.js"
|
||||
export const AddNewComplaint = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
|
||||
// req.body.user = req.user._id
|
||||
const complaint = await Complaint.create(req.body);
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
complaint,
|
||||
message: 'Complaint Added',
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : 'Something went Wrong',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const FindAllComplaint = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
|
||||
const complaint = await Complaint.find().sort({ createdAt: -1 });
|
||||
if (complaint) {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
complaint,
|
||||
message: 'Fetched All Complaint',
|
||||
});
|
||||
}
|
||||
else {
|
||||
return res.status(404).json({
|
||||
success: true,
|
||||
|
||||
message: 'No Complaint till Now',
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : 'Something went Wrong',
|
||||
});
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
import mongoose from "mongoose";
|
||||
|
||||
const { Schema, model } = mongoose;
|
||||
|
||||
const ComplaintSchema = new mongoose.Schema(
|
||||
{
|
||||
|
||||
MobileOrEmail: {
|
||||
type: String,
|
||||
maxLength: [150, "Mobile Or Email cannot exceed 25 characters"],
|
||||
required: [true, "Please Enter Mobile Or Email "],
|
||||
},
|
||||
Complaint: {
|
||||
type: String,
|
||||
maxLength: [1000, "Complaint cannot exceed 1000 characters"],
|
||||
required: [true, "Please Enter Complaint"],
|
||||
},
|
||||
|
||||
},
|
||||
{ timestamps: true, versionKey: false }
|
||||
);
|
||||
|
||||
export const Complaint = mongoose.model("Complaint", ComplaintSchema);
|
@ -1,18 +0,0 @@
|
||||
|
||||
import express from 'express'
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||
import { AddNewComplaint, FindAllComplaint } from './ComplaintController.js';
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
router.route("/new").post(isAuthenticatedUser, AddNewComplaint)
|
||||
router.route("/getAll").get(isAuthenticatedUser, authorizeRoles("admin"), FindAllComplaint)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// router.route("/product/getAll/").get(getAllProduct)
|
||||
|
||||
export default router
|
@ -7,7 +7,6 @@ import cloudinary from "../../Utils/cloudinary.js";
|
||||
export const createProduct = async (req, res) => {
|
||||
|
||||
try {
|
||||
// console.log(req.body)
|
||||
if (!req.files) {
|
||||
return res.status(400).json({
|
||||
|
||||
@ -15,30 +14,38 @@ export const createProduct = async (req, res) => {
|
||||
|
||||
});
|
||||
}
|
||||
const image_file = req.files.image;
|
||||
let images = [];
|
||||
let Allfiles = req.files.image;
|
||||
if (typeof Allfiles.tempFilePath === "string") {
|
||||
let filepath = Allfiles.tempFilePath;
|
||||
|
||||
|
||||
|
||||
const myCloud = await cloudinary.v2.uploader.upload(
|
||||
image_file?.tempFilePath,
|
||||
{
|
||||
folder: "ATP/Product_Image",
|
||||
images.push(filepath)
|
||||
} else {
|
||||
Allfiles.map(item => {
|
||||
images.push(item.tempFilePath);
|
||||
})
|
||||
}
|
||||
);
|
||||
// const { name, base, description, date, time } = req.body;
|
||||
|
||||
const data = await Product.create({
|
||||
...req.body,
|
||||
|
||||
image: {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
},
|
||||
|
||||
|
||||
const imagesLinks = [];
|
||||
for (let i = 0; i < images.length; i++) {
|
||||
const result = await cloudinary.v2.uploader.upload(images[i], {
|
||||
folder: "jatinMor/product",
|
||||
});
|
||||
|
||||
imagesLinks.push({
|
||||
public_id: result.public_id,
|
||||
url: result.secure_url,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
req.body.image = imagesLinks;
|
||||
req.body.addedBy = req.user.id;
|
||||
|
||||
const data = await Product.create({ ...req.body });
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
data,
|
||||
msg: " create Product Successfully!!",
|
||||
|
||||
});
|
||||
@ -96,45 +103,57 @@ export const getOneProduct = async (req, res) => {
|
||||
// 3.update Product
|
||||
export const updateProduct = async (req, res) => {
|
||||
try {
|
||||
const newProductData = {
|
||||
name: req.body.name,
|
||||
description: req.body.description,
|
||||
base_Price: req.body.base_Price,
|
||||
base_Price_With_Tax: req.body.base_Price_With_Tax,
|
||||
price_Level_2: req.body.price_Level_2,
|
||||
price_Level_2_With_Tax: req.body.price_Level_2_With_Tax,
|
||||
price_Level_3: req.body.price_Level_3,
|
||||
price_Level_3_With_Tax: req.body.price_Level_3_With_Tax,
|
||||
// const newProductData = {
|
||||
// name: req.body.name,
|
||||
// description: req.body.description,
|
||||
// price: req.body.base_Price,
|
||||
|
||||
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
if (req.files) {
|
||||
const image_file = req.files.image;
|
||||
|
||||
|
||||
// req.body.addedBy = req.user.id;
|
||||
// const image_file = req.files.image;
|
||||
const getProduct = await Product.findById(req.params.id);
|
||||
|
||||
|
||||
if (getProduct) {
|
||||
const imageId = getProduct.image.public_id;
|
||||
//delete image from claudinary
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
// Deleting Images From Cloudinary
|
||||
for (let i = 0; i < getProduct.image.length; i++) {
|
||||
await cloudinary.v2.uploader.destroy(getProduct.image[i].public_id);
|
||||
}
|
||||
}
|
||||
let images = [];
|
||||
let Allfiles = req.files.image;
|
||||
if (typeof Allfiles.tempFilePath === "string") {
|
||||
let filepath = Allfiles.tempFilePath;
|
||||
|
||||
images.push(filepath)
|
||||
} else {
|
||||
Allfiles.map(item => {
|
||||
images.push(item.tempFilePath);
|
||||
})
|
||||
}
|
||||
|
||||
const imagesLinks = [];
|
||||
for (let i = 0; i < images.length; i++) {
|
||||
const result = await cloudinary.v2.uploader.upload(images[i], {
|
||||
folder: "jatinMor/product",
|
||||
});
|
||||
|
||||
imagesLinks.push({
|
||||
public_id: result.public_id,
|
||||
url: result.secure_url,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const myCloud = await cloudinary.v2.uploader.upload(
|
||||
image_file?.tempFilePath,
|
||||
{
|
||||
folder: "ATP/Product_Image",
|
||||
req.body.image = imagesLinks;
|
||||
}
|
||||
);
|
||||
// console.log(myCloud)
|
||||
newProductData.image = {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
};
|
||||
}
|
||||
// console.log(newCategoryData)
|
||||
//req.user.id,
|
||||
const ModifyProduct = await Product.findByIdAndUpdate(req.params.id, newProductData,
|
||||
|
||||
|
||||
const ModifyProduct = await Product.findByIdAndUpdate(req.params.id, req.body,
|
||||
|
||||
{ new: true }
|
||||
// runValidators: true,
|
||||
@ -161,9 +180,14 @@ export const updateProduct = async (req, res) => {
|
||||
export const deleteProduct = async (req, res) => {
|
||||
|
||||
try {
|
||||
//delete image from cloudinary
|
||||
|
||||
if (!req.params.id) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
msg: "Please Provide Product ID!"
|
||||
});
|
||||
}
|
||||
const getProduct = await Product.findById(req.params.id);
|
||||
// console.log(categ)
|
||||
if (!getProduct) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
@ -171,8 +195,11 @@ export const deleteProduct = async (req, res) => {
|
||||
});
|
||||
|
||||
}
|
||||
const imageId = getProduct.image.public_id;
|
||||
await cloudinary.uploader.destroy(imageId)
|
||||
// Deleting Images From Cloudinary
|
||||
for (let i = 0; i < getProduct.image.length; i++) {
|
||||
await cloudinary.v2.uploader.destroy(getProduct.image[i].public_id);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------//
|
||||
const product = await Product.findByIdAndDelete(req.params.id)
|
||||
|
@ -13,47 +13,15 @@ const productSchema = new Schema({
|
||||
maxLength: [100, "description cannot exceed 100 characters"],
|
||||
required: [true, "Please Enter product Description"],
|
||||
},
|
||||
base_Price: {
|
||||
type: Number,
|
||||
required: [true, "Please Enter product Price"],
|
||||
maxLength: [8, "Price cannot exceed 8 characters"],
|
||||
},
|
||||
base_Price_With_Tax: {
|
||||
price: {
|
||||
type: Number,
|
||||
required: [true, "Please Enter product Price"],
|
||||
maxLength: [8, "Price cannot exceed 8 characters"],
|
||||
},
|
||||
|
||||
price_Level_2: {
|
||||
type: Number,
|
||||
required: true,
|
||||
|
||||
maxLength: [8, "price leval2 cannot exceed 8 characters"],
|
||||
},
|
||||
price_Level_2_With_Tax: {
|
||||
type: Number,
|
||||
required: [true, "Please Enter product Price"],
|
||||
maxLength: [8, "Price cannot exceed 8 characters"],
|
||||
},
|
||||
|
||||
price_Level_3: {
|
||||
type: Number,
|
||||
required: true,
|
||||
|
||||
maxLength: [8, "price leval3 cannot exceed 8 characters"],
|
||||
},
|
||||
price_Level_3_With_Tax: {
|
||||
type: Number,
|
||||
required: [true, "Please Enter product Price"],
|
||||
maxLength: [8, "Price cannot exceed 8 characters"],
|
||||
},
|
||||
taxId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
|
||||
ref: "Tax"
|
||||
},
|
||||
|
||||
image:
|
||||
image: [
|
||||
{
|
||||
public_id: {
|
||||
type: String,
|
||||
@ -64,7 +32,11 @@ const productSchema = new Schema({
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
],
|
||||
addedBy: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'User'
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
91
resources/Testimonials/TestimonialController.js
Normal file
91
resources/Testimonials/TestimonialController.js
Normal file
@ -0,0 +1,91 @@
|
||||
|
||||
import cloudinary from "../../Utils/cloudinary.js";
|
||||
import { Testimonial } from "./TestimonialModel.js"
|
||||
export const AddNewTestimonial = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
if (req.files) {
|
||||
let getImg = req.files.image
|
||||
const result = await cloudinary.v2.uploader.upload(getImg?.tempFilePath, {
|
||||
folder: "jatinMor/Testimonial",
|
||||
})
|
||||
|
||||
let simage = {
|
||||
public_id: result.public_id,
|
||||
url: result.secure_url,
|
||||
}
|
||||
req.body.image = simage
|
||||
|
||||
}
|
||||
|
||||
req.body.user = req.user._id
|
||||
const testimonial = await Testimonial.create(req.body);
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
testimonial,
|
||||
message: 'Testimonial Added',
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : 'Something went Wrong',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const FindAllTestimonial = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
|
||||
const testimonial = await Testimonial.find().sort({ createdAt: -1 });
|
||||
if (testimonial) {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
testimonial,
|
||||
message: 'Fetched All Testimonial',
|
||||
});
|
||||
}
|
||||
else {
|
||||
return res.status(404).json({
|
||||
success: true,
|
||||
|
||||
message: 'No Testimonial till Now',
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : 'Something went Wrong',
|
||||
});
|
||||
}
|
||||
}
|
||||
export const FindOneTestimonial = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
if (!req.params.id) return res.status(400).json({ message: "please give ID !" });
|
||||
|
||||
|
||||
const testimonial = await Testimonial.findById(req.params.id);
|
||||
if (testimonial) {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
testimonial,
|
||||
message: 'Fetched Testimonial',
|
||||
});
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : 'Something went Wrong',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
42
resources/Testimonials/TestimonialModel.js
Normal file
42
resources/Testimonials/TestimonialModel.js
Normal file
@ -0,0 +1,42 @@
|
||||
import mongoose from "mongoose";
|
||||
|
||||
const { Schema, model } = mongoose;
|
||||
|
||||
const TestimonialSchema = new mongoose.Schema(
|
||||
{
|
||||
|
||||
name: {
|
||||
type: String,
|
||||
maxLength: [150, "name cannot exceed 25 characters"],
|
||||
required: [true, "Please Enter name "],
|
||||
},
|
||||
company: {
|
||||
type: String,
|
||||
maxLength: [30, "company name cannot exceed 1000 characters"],
|
||||
default: ''
|
||||
},
|
||||
testimonial: {
|
||||
type: String,
|
||||
maxLength: [1000, "testimonial cannot exceed 1000 characters"],
|
||||
required: [true, "Please Enter testimonial"],
|
||||
},
|
||||
image: {
|
||||
public_id: {
|
||||
type: String,
|
||||
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
|
||||
},
|
||||
},
|
||||
user: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'User'
|
||||
}
|
||||
|
||||
},
|
||||
{ timestamps: true, versionKey: false }
|
||||
);
|
||||
|
||||
export const Testimonial = mongoose.model("Testimonial", TestimonialSchema);
|
20
resources/Testimonials/TestimonialRoute.js
Normal file
20
resources/Testimonials/TestimonialRoute.js
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
import express from 'express'
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||
import { AddNewTestimonial, FindAllTestimonial, FindOneTestimonial } from './TestimonialController.js';
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
router.route("/new").post(isAuthenticatedUser, AddNewTestimonial)
|
||||
router.route("/getAll").get(isAuthenticatedUser, authorizeRoles("admin"), FindAllTestimonial)
|
||||
router.route("/getOne/:id").get(isAuthenticatedUser, FindOneTestimonial)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// router.route("/product/getAll/").get(getAllProduct)
|
||||
|
||||
export default router
|
@ -286,14 +286,14 @@ const addLogo = async (req, res) => {
|
||||
|
||||
const result = await cloudinary.v2.uploader.upload(
|
||||
req.files.Headerlogo.tempFilePath,
|
||||
{ folder: "ATP/Logo" }
|
||||
{ folder: "Jatin/Logo" }
|
||||
);
|
||||
result1 = result.secure_url;
|
||||
}
|
||||
if (req.files.Footerlogo) {
|
||||
const result = await cloudinary.v2.uploader.upload(
|
||||
req.files.Footerlogo.tempFilePath,
|
||||
{ folder: "ATP/Logo" }
|
||||
{ folder: "Jatin/Logo" }
|
||||
);
|
||||
result2 = result.secure_url;
|
||||
}
|
||||
@ -301,7 +301,7 @@ const addLogo = async (req, res) => {
|
||||
// console.log(req.files.Adminlogo.path)
|
||||
const result = await cloudinary.v2.uploader.upload(
|
||||
req.files.Adminlogo.tempFilePath,
|
||||
{ folder: "ATP/Logo" }
|
||||
{ folder: "Jatin/Logo" }
|
||||
);
|
||||
result3 = result.secure_url;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ export const forgotPassword = async (req, res, next) => {
|
||||
|
||||
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
||||
|
||||
subject: `ChatGpt Airport Password Recovery`,
|
||||
subject: `JAtin Mor Password Recovery`,
|
||||
html: `your new password is: <br/> <strong> ${passwords}</strong><br/><br/>If you have not requested this email then, please ignore it.`
|
||||
|
||||
});
|
||||
|
@ -2,11 +2,11 @@
|
||||
import dotenv from 'dotenv'
|
||||
dotenv.config()
|
||||
import app from "./app.js"
|
||||
import connectDatabase from "./database/db.js";
|
||||
import connectDatabase from "./database/db.js"
|
||||
import cloudinary from "cloudinary"
|
||||
|
||||
// Connecting to database
|
||||
connectDatabase();
|
||||
connectDatabase()
|
||||
|
||||
//console.log(process.env.CLOUDINARY_API_KEY)
|
||||
//cloudenary uses
|
||||
|
Loading…
Reference in New Issue
Block a user