From f1c90c9d3e00f593fbf2eee2c678fb6b8899da8f Mon Sep 17 00:00:00 2001
From: pawan-dot <71133473+pawan-dot@users.noreply.github.com>
Date: Thu, 2 Mar 2023 21:59:22 +0530
Subject: [PATCH] first commit
---
.env | 21 +--
app.js | 8 +-
database/db.js | 3 +-
resources/Complaints/ComplaintController.js | 53 -------
resources/Complaints/ComplaintModel.js | 23 ---
resources/Complaints/ComplaintRoute.js | 18 ---
resources/Products/ProductController.js | 135 +++++++++++-------
resources/Products/ProductModel.js | 60 +++-----
.../Testimonials/TestimonialController.js | 91 ++++++++++++
resources/Testimonials/TestimonialModel.js | 42 ++++++
resources/Testimonials/TestimonialRoute.js | 20 +++
.../setting/Configration/Config_controller.js | 6 +-
resources/user/userController.js | 2 +-
server.js | 4 +-
14 files changed, 273 insertions(+), 213 deletions(-)
delete mode 100644 resources/Complaints/ComplaintController.js
delete mode 100644 resources/Complaints/ComplaintModel.js
delete mode 100644 resources/Complaints/ComplaintRoute.js
create mode 100644 resources/Testimonials/TestimonialController.js
create mode 100644 resources/Testimonials/TestimonialModel.js
create mode 100644 resources/Testimonials/TestimonialRoute.js
diff --git a/.env b/.env
index 524e907..0b02ba7 100644
--- a/.env
+++ b/.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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"
\ No newline at end of file
+# Jatin Mor
+SENDGRID_API_KEY="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"
\ No newline at end of file
diff --git a/app.js b/app.js
index 0b10df5..42a1ec8 100644
--- a/app.js
+++ b/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
diff --git a/database/db.js b/database/db.js
index 8c8d87e..b5e80be 100644
--- a/database/db.js
+++ b/database/db.js
@@ -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;
diff --git a/resources/Complaints/ComplaintController.js b/resources/Complaints/ComplaintController.js
deleted file mode 100644
index 3f26c36..0000000
--- a/resources/Complaints/ComplaintController.js
+++ /dev/null
@@ -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',
- });
- }
-}
diff --git a/resources/Complaints/ComplaintModel.js b/resources/Complaints/ComplaintModel.js
deleted file mode 100644
index ff062be..0000000
--- a/resources/Complaints/ComplaintModel.js
+++ /dev/null
@@ -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);
diff --git a/resources/Complaints/ComplaintRoute.js b/resources/Complaints/ComplaintRoute.js
deleted file mode 100644
index 772e313..0000000
--- a/resources/Complaints/ComplaintRoute.js
+++ /dev/null
@@ -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
\ No newline at end of file
diff --git a/resources/Products/ProductController.js b/resources/Products/ProductController.js
index 57fe6cc..45c3717 100644
--- a/resources/Products/ProductController.js
+++ b/resources/Products/ProductController.js
@@ -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;
+
+ 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,
+ });
+ }
+ req.body.image = imagesLinks;
+ req.body.addedBy = req.user.id;
- const myCloud = await cloudinary.v2.uploader.upload(
- image_file?.tempFilePath,
- {
- folder: "ATP/Product_Image",
- }
- );
- // 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 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",
- }
- );
- // console.log(myCloud)
- newProductData.image = {
- public_id: myCloud.public_id,
- url: myCloud.secure_url,
- };
+ req.body.image = imagesLinks;
}
- // 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)
diff --git a/resources/Products/ProductModel.js b/resources/Products/ProductModel.js
index 0b77293..1171889 100644
--- a/resources/Products/ProductModel.js
+++ b/resources/Products/ProductModel.js
@@ -13,58 +13,30 @@ 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: {
+ image: [
+ {
+ public_id: {
+ type: String,
+ required: true,
+ },
+ url: {
+ type: String,
+ required: true,
+ },
+ },
+ ],
+ addedBy: {
type: Schema.Types.ObjectId,
-
- ref: "Tax"
- },
-
- image:
- {
- public_id: {
- type: String,
- required: true,
- },
- url: {
- type: String,
- required: true,
- },
- },
-
+ ref: 'User'
+ }
diff --git a/resources/Testimonials/TestimonialController.js b/resources/Testimonials/TestimonialController.js
new file mode 100644
index 0000000..bcd532f
--- /dev/null
+++ b/resources/Testimonials/TestimonialController.js
@@ -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',
+ });
+ }
+}
+
diff --git a/resources/Testimonials/TestimonialModel.js b/resources/Testimonials/TestimonialModel.js
new file mode 100644
index 0000000..a085fd4
--- /dev/null
+++ b/resources/Testimonials/TestimonialModel.js
@@ -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);
diff --git a/resources/Testimonials/TestimonialRoute.js b/resources/Testimonials/TestimonialRoute.js
new file mode 100644
index 0000000..97b6bb2
--- /dev/null
+++ b/resources/Testimonials/TestimonialRoute.js
@@ -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
\ No newline at end of file
diff --git a/resources/setting/Configration/Config_controller.js b/resources/setting/Configration/Config_controller.js
index f4734cc..fe663e1 100644
--- a/resources/setting/Configration/Config_controller.js
+++ b/resources/setting/Configration/Config_controller.js
@@ -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;
}
diff --git a/resources/user/userController.js b/resources/user/userController.js
index ce2f0f2..991ae51 100644
--- a/resources/user/userController.js
+++ b/resources/user/userController.js
@@ -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:
${passwords}
If you have not requested this email then, please ignore it.`
});
diff --git a/server.js b/server.js
index 91a55d7..39f7b03 100644
--- a/server.js
+++ b/server.js
@@ -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