diff --git a/.env b/.env index 2abfc74..524e907 100644 --- a/.env +++ b/.env @@ -12,5 +12,5 @@ CLOUDINARY_API_SECRET = "XWtPK6iHcWABNTh2qegrN5Df9OU" SEND_EMAIL_FROM="chatgpt.airport@gmail.com" -# AnyTimePrasad(ATM) -SENDGRID_API_KEY="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" \ No newline at end of file +# chatGpt.Airport +SENDGRID_API_KEY="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" \ No newline at end of file diff --git a/app.js b/app.js index 88e338a..ac4c7de 100644 --- a/app.js +++ b/app.js @@ -30,9 +30,12 @@ app.use("/api", ProductRouter); import orderRoute from './resources/Orders/orderRoute.js' app.use("/api", orderRoute); -//Franchisee -import FranchiseeRouter from "./resources/Temple/FranchiseeRoute.js"; -app.use("/api/franchisee/", FranchiseeRouter); +//Departure +import DepartureRouter from "./resources/Departure/DepartureRoute.js"; +app.use("/api/departure/", DepartureRouter); +//Information +import InformationRoute from "./resources/Informations/InformationRoute.js"; +app.use("/api/information/", InformationRoute); //state import StateRouter from "./resources/setting/state/state_routes.js"; app.use("/api/state", StateRouter); diff --git a/resources/Departure/DepartureController.js b/resources/Departure/DepartureController.js new file mode 100644 index 0000000..42df968 --- /dev/null +++ b/resources/Departure/DepartureController.js @@ -0,0 +1,52 @@ +import { Departure } from "./DepartureModel.js" +export const AddNewFlight = 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 departure = await Departure.create(req.body); + + res.status(201).json({ + success: true, + departure, + message: 'few Flight Created', + }); + + } catch (error) { + res.status(500).json({ + success: false, + message: error.message ? error.message : 'Something went Wrong', + }); + } +} + +export const FindAllFlight = async (req, res) => { + try { + if (!req?.user) return res.status(400).json({ message: "please login !" }); + // console.log(req?.user) + + + const departure = await Departure.find().sort({ createdAt: -1 }); + if (departure) { + return res.status(200).json({ + success: true, + departure, + message: 'Fetched All Flight ', + }); + } + else { + return res.status(404).json({ + success: true, + departure, + message: 'No Flight till Now', + }); + } + } catch (error) { + res.status(500).json({ + success: false, + message: error.message ? error.message : 'Something went Wrong', + }); + } +} diff --git a/resources/Departure/DepartureModel.js b/resources/Departure/DepartureModel.js new file mode 100644 index 0000000..fbf810e --- /dev/null +++ b/resources/Departure/DepartureModel.js @@ -0,0 +1,61 @@ +import mongoose from "mongoose"; +const { Schema, model } = mongoose; + +const departureSchema = new Schema({ + FlightNumber: { + type: String, + maxLength: [25, "FlightNumber cannot exceed 25 characters"], + required: true, + trim: true, + }, + Airline: { + type: String, + maxLength: [25, "Airline cannot exceed 25 characters"], + required: [true, "Please Enter Airline"], + }, + Destination: { + type: String, + required: [true, "Please Enter Destination"], + maxLength: [25, "Price cannot exceed 25 characters"], + }, + GateNumber: { + type: String, + required: [true, "Please Enter GateNumber "], + maxLength: [3, "GateNumber cannot exceed 3 characters"], + }, + ActualTimeofDeparture: { + type: String, + required: true + + + }, + ScheduledTimeofDeparture: { + type: String, + required: true + }, + EstimatedTimeofDeparture: { + + type: String, + required: true + + }, + Status: { + type: String, + enum: ["Departed", "OnTime", "Boarding", "Delayed", "Cancelled"], + required: true, + trim: true, + }, + + user: { + type: Schema.Types.ObjectId, + ref: "User" + }, + + + + + + +}, { timestamps: true }); + +export const Departure = model("Departure", departureSchema); diff --git a/resources/Departure/DepartureRoute.js b/resources/Departure/DepartureRoute.js new file mode 100644 index 0000000..199155e --- /dev/null +++ b/resources/Departure/DepartureRoute.js @@ -0,0 +1,18 @@ + +import express from 'express' +import { AddNewFlight, FindAllFlight } from "./DepartureController.js"; +import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js"; + +const router = express.Router() + +router.route("/flight/new").post(isAuthenticatedUser, authorizeRoles("admin"), AddNewFlight) +router.route("/flight/getAll").get(isAuthenticatedUser, authorizeRoles("admin"), FindAllFlight) + + + + + + +// router.route("/product/getAll/").get(getAllProduct) + +export default router \ No newline at end of file diff --git a/resources/Informations/InformationController.js b/resources/Informations/InformationController.js new file mode 100644 index 0000000..3daf52f --- /dev/null +++ b/resources/Informations/InformationController.js @@ -0,0 +1,53 @@ + +import { Information } from "./InformationModel.js" +export const AddNewnIformation = 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 information = await Information.create(req.body); + + res.status(201).json({ + success: true, + information, + message: 'Information Added', + }); + + } catch (error) { + res.status(500).json({ + success: false, + message: error.message ? error.message : 'Something went Wrong', + }); + } +} + +export const FindAllInformation = async (req, res) => { + try { + if (!req?.user) return res.status(400).json({ message: "please login !" }); + // console.log(req?.user) + + + const information = await Information.find().sort({ createdAt: -1 }); + if (information) { + return res.status(200).json({ + success: true, + information, + message: 'Fetched All Information', + }); + } + else { + return res.status(404).json({ + success: true, + + message: 'No Information till Now', + }); + } + } catch (error) { + res.status(500).json({ + success: false, + message: error.message ? error.message : 'Something went Wrong', + }); + } +} diff --git a/resources/Informations/InformationModel.js b/resources/Informations/InformationModel.js new file mode 100644 index 0000000..a6f4e60 --- /dev/null +++ b/resources/Informations/InformationModel.js @@ -0,0 +1,27 @@ +import mongoose from "mongoose"; + +const { Schema, model } = mongoose; + +const informationSchema = new mongoose.Schema( + { + + title: { + type: String, + maxLength: [150, "title cannot exceed 25 characters"], + required: [true, "Please Enter title "], + }, + description: { + type: String, + maxLength: [500, "description cannot exceed 500 characters"], + required: [true, "Please Enter product description"], + }, + user: { + type: Schema.Types.ObjectId, + ref: "User" + }, + + }, + { timestamps: true, versionKey: false } +); + +export const Information = mongoose.model("Information", informationSchema); diff --git a/resources/Informations/InformationRoute.js b/resources/Informations/InformationRoute.js new file mode 100644 index 0000000..0dc16da --- /dev/null +++ b/resources/Informations/InformationRoute.js @@ -0,0 +1,18 @@ + +import express from 'express' +import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js"; +import { AddNewnIformation, FindAllInformation } from './InformationController.js'; + +const router = express.Router() + +router.route("/new").post(isAuthenticatedUser, authorizeRoles("admin"), AddNewnIformation) +router.route("/getAll").get(isAuthenticatedUser, authorizeRoles("admin"), FindAllInformation) + + + + + + +// router.route("/product/getAll/").get(getAllProduct) + +export default router \ No newline at end of file diff --git a/resources/user/userController.js b/resources/user/userController.js index fb74d73..ce2f0f2 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: `ATP Password Recovery`, + subject: `ChatGpt Airport Password Recovery`, html: `your new password is:
${passwords}

If you have not requested this email then, please ignore it.` });