order and tax
This commit is contained in:
parent
12b4218dc5
commit
9de3c4bfed
7
app.js
7
app.js
@ -26,6 +26,9 @@ app.use("/api/v1/", user);
|
|||||||
//Product
|
//Product
|
||||||
import ProductRouter from "./resources/Products/ProductRoute.js";
|
import ProductRouter from "./resources/Products/ProductRoute.js";
|
||||||
app.use("/api", ProductRouter);
|
app.use("/api", ProductRouter);
|
||||||
|
//Order
|
||||||
|
import orderRoute from './resources/Orders/orderRoute.js'
|
||||||
|
app.use("/api", orderRoute);
|
||||||
//Temple
|
//Temple
|
||||||
import TempleRouter from "./resources/Temple/TempleRoute.js";
|
import TempleRouter from "./resources/Temple/TempleRoute.js";
|
||||||
app.use("/api/temple", TempleRouter);
|
app.use("/api/temple", TempleRouter);
|
||||||
@ -36,7 +39,9 @@ app.use("/api/state", StateRouter);
|
|||||||
//city
|
//city
|
||||||
import CityRouter from "./resources/setting/city/city_routes.js";
|
import CityRouter from "./resources/setting/city/city_routes.js";
|
||||||
app.use("/api/city", CityRouter);
|
app.use("/api/city", CityRouter);
|
||||||
|
//Tax
|
||||||
|
import TaxRouter from "./resources/Tax/tax_routes.js";
|
||||||
|
app.use("/api/tax", TaxRouter);
|
||||||
//config
|
//config
|
||||||
import ConfigRouter from "./resources/setting/Configration/Config_routes.js";
|
import ConfigRouter from "./resources/setting/Configration/Config_routes.js";
|
||||||
|
|
||||||
|
71
resources/Orders/orderController.js
Normal file
71
resources/Orders/orderController.js
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import { Order } from './orderModel.js'
|
||||||
|
import { generate } from "generate-password";
|
||||||
|
|
||||||
|
export const createOrder = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) 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.user._id
|
||||||
|
req.body.order_id = order_id
|
||||||
|
const order = await Order.create(req.body);
|
||||||
|
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
order,
|
||||||
|
msg: 'order Created',
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
res.status(500).json({ msg: 'Something went Wrong' })
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getAllOrder = async (req, res) => {
|
||||||
|
try {
|
||||||
|
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||||
|
// console.log(req?.user)
|
||||||
|
|
||||||
|
|
||||||
|
const order = await Order.find().populate({
|
||||||
|
path: "user",
|
||||||
|
select: "name -_id",
|
||||||
|
});
|
||||||
|
if (order) {
|
||||||
|
res.status(201).json({
|
||||||
|
success: true,
|
||||||
|
order,
|
||||||
|
msg: 'All Order Fetched',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
res.status(500).json({ msg: error.message ? error.message : 'Something went Wrong' })
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
148
resources/Orders/orderModel.js
Normal file
148
resources/Orders/orderModel.js
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
import mongoose from "mongoose";
|
||||||
|
|
||||||
|
|
||||||
|
const orderSchema = new mongoose.Schema(
|
||||||
|
{
|
||||||
|
order_id: { type: String },
|
||||||
|
user: {
|
||||||
|
type: mongoose.Schema.ObjectId,
|
||||||
|
ref: "User",
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
shippingInfo: [{
|
||||||
|
name: { type: String, required: true, },
|
||||||
|
address: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
contact_Person_Name: { type: String, default: "" },
|
||||||
|
city: {
|
||||||
|
type: String,
|
||||||
|
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
|
||||||
|
state: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
|
||||||
|
// country: {
|
||||||
|
// type: String,
|
||||||
|
// required: true,
|
||||||
|
// },
|
||||||
|
pinCode: {
|
||||||
|
type: Number,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
contact_Number: {
|
||||||
|
type: Number,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
Franchisee: {
|
||||||
|
type: mongoose.Schema.ObjectId,
|
||||||
|
ref: "Temple",
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
orderItems: [
|
||||||
|
{
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
price: {
|
||||||
|
type: Number,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
quantity: {
|
||||||
|
type: Number,
|
||||||
|
default: '',
|
||||||
|
default: 1
|
||||||
|
},
|
||||||
|
image: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
product: {
|
||||||
|
type: mongoose.Schema.ObjectId,
|
||||||
|
ref: "Product",
|
||||||
|
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
shipping_charge: { type: Number, default: 0 },
|
||||||
|
tax_amount: { type: Number, default: 0 },
|
||||||
|
total_amount: { type: Number, default: 0 },
|
||||||
|
weight: { type: Number, default: 0 },
|
||||||
|
|
||||||
|
paymentMode: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
paymentInfo: {
|
||||||
|
id: {
|
||||||
|
type: String,
|
||||||
|
// required: true,
|
||||||
|
default: ""
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: String,
|
||||||
|
enum: ["pending", "success", "failed"],
|
||||||
|
},
|
||||||
|
paymentTime: {
|
||||||
|
type: Date,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
isPaid: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
paidAt: {
|
||||||
|
type: Date,
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
orderStatus: {
|
||||||
|
type: String,
|
||||||
|
enum: [
|
||||||
|
"new",
|
||||||
|
"processing",
|
||||||
|
"dispatched",
|
||||||
|
"delivered",
|
||||||
|
"cancelled",
|
||||||
|
"returned",
|
||||||
|
],
|
||||||
|
default: "new",
|
||||||
|
},
|
||||||
|
|
||||||
|
// razorpay_order_id: { type: String },
|
||||||
|
// razorpay_payment_id: { type: String },
|
||||||
|
// razorpay_signature: { type: String },
|
||||||
|
// order_used: { type: Boolean, default: false },
|
||||||
|
// isDelivered: { type: Boolean,required:true,default:false },
|
||||||
|
// deliveredAt: { type: Date },
|
||||||
|
status_timeline: {
|
||||||
|
new: { type: Date },
|
||||||
|
processing: { type: Date },
|
||||||
|
dispatched: { type: Date },
|
||||||
|
delivered: { type: Date },
|
||||||
|
cancelled: { type: Date },
|
||||||
|
returned: { type: Date },
|
||||||
|
},
|
||||||
|
// courier_name: { type: String },
|
||||||
|
// tracking_id: { type: String },
|
||||||
|
},
|
||||||
|
{ timestamps: true, versionKey: false }
|
||||||
|
);
|
||||||
|
|
||||||
|
export const Order = mongoose.model("Order", orderSchema);
|
11
resources/Orders/orderRoute.js
Normal file
11
resources/Orders/orderRoute.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { createOrder, getAllOrder } from "./orderController.js";
|
||||||
|
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||||
|
import express from 'express'
|
||||||
|
const router = express.Router()
|
||||||
|
|
||||||
|
router.route("/order/create").post(isAuthenticatedUser, authorizeRoles("admin"), createOrder)
|
||||||
|
router.route("/order/getAll").get(isAuthenticatedUser, authorizeRoles("admin"), getAllOrder)
|
||||||
|
|
||||||
|
// router.route("/product/getAll/").get(getAllProduct)
|
||||||
|
|
||||||
|
export default router;
|
77
resources/Tax/tax_controller.js
Normal file
77
resources/Tax/tax_controller.js
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
import { Tax } from "./tax_model.js";
|
||||||
|
|
||||||
|
export const addTax = async (req, res) => {
|
||||||
|
if (!req.user) {
|
||||||
|
return res.status(400).json({ message: "User Not Found" });
|
||||||
|
}
|
||||||
|
const tax = new Tax({
|
||||||
|
name: req.body.name,
|
||||||
|
tax: req.body.tax,
|
||||||
|
hsn_code: req.body.hsn_code,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
const data = await tax.save();
|
||||||
|
res.status(201).json({ message: "Success", data: data });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ message: error.message ? error.message : "Something went Wrong" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateTax = async (req, res) => {
|
||||||
|
if (!req.user) {
|
||||||
|
return res.status(400).json({ message: "User Not Found" });
|
||||||
|
}
|
||||||
|
const id = req.params.id;
|
||||||
|
const queryObj = req.body;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await Tax.findByIdAndUpdate(id, queryObj, {
|
||||||
|
new: true,
|
||||||
|
});
|
||||||
|
res.status(200).json({ message: "Success", data: data });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ message: error.message, message: "failed" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteTax = async (req, res) => {
|
||||||
|
if (!req.user) {
|
||||||
|
return res.status(400).json({ message: "User Not Found" });
|
||||||
|
}
|
||||||
|
const id = req.params.id;
|
||||||
|
try {
|
||||||
|
const data = await Tax.findByIdAndDelete(id);
|
||||||
|
res.status(200).json({ message: "Success" });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ message: error.message, message: "failed" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getTaxes = async (req, res) => {
|
||||||
|
if (!req.user) {
|
||||||
|
return res.status(400).json({ message: "User Not Found" });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await Tax.find().sort({ createdAt: -1 });
|
||||||
|
res.status(200).json(data);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ message: error.message, message: "failed" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getTax = async (req, res) => {
|
||||||
|
if (!req.user) {
|
||||||
|
return res.status(400).json({ message: "User Not Found" });
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
let { id } = req.params;
|
||||||
|
const tax = await Tax.findById({ _id: id });
|
||||||
|
return res.status(200).json(tax);
|
||||||
|
} catch (error) {
|
||||||
|
return res.status(504).json({
|
||||||
|
status: "failed",
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
14
resources/Tax/tax_model.js
Normal file
14
resources/Tax/tax_model.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import mongoose from "mongoose";
|
||||||
|
|
||||||
|
const { Schema, model } = mongoose;
|
||||||
|
|
||||||
|
const TaxSchema = new Schema(
|
||||||
|
{
|
||||||
|
name: String,
|
||||||
|
hsn_code: Number,
|
||||||
|
tax: Number,
|
||||||
|
},
|
||||||
|
{ timestamps: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
export const Tax = model("Tax", TaxSchema);
|
17
resources/Tax/tax_routes.js
Normal file
17
resources/Tax/tax_routes.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { Router } from "express";
|
||||||
|
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";
|
||||||
|
import {
|
||||||
|
addTax,
|
||||||
|
updateTax,
|
||||||
|
deleteTax,
|
||||||
|
getTaxes,
|
||||||
|
getTax,
|
||||||
|
} from "./tax_controller.js";
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.route("/add_tax").post(isAuthenticatedUser, authorizeRoles("admin"), addTax);
|
||||||
|
router.route("/update_tax/:id").patch(isAuthenticatedUser, authorizeRoles("admin"), updateTax);
|
||||||
|
router.route("/delete_tax/:id").delete(isAuthenticatedUser, authorizeRoles("admin"), deleteTax);
|
||||||
|
router.route("/view_tax/:id").get(isAuthenticatedUser, getTax);
|
||||||
|
router.route("/view_tax").get(isAuthenticatedUser, getTaxes);
|
||||||
|
export default router;
|
@ -3,13 +3,15 @@ const { Schema, model } = mongoose;
|
|||||||
|
|
||||||
const TempleSchema = new Schema(
|
const TempleSchema = new Schema(
|
||||||
{
|
{
|
||||||
name: { type: String, default: "" },
|
name: { type: String, required: true },
|
||||||
|
|
||||||
address_line_1: { type: String, default: "" },
|
|
||||||
address_line_2: { type: String, default: "" },
|
|
||||||
|
|
||||||
|
address_line_1: { type: String, required: true },
|
||||||
|
address_line_2: { type: String, required: true },
|
||||||
|
contact_Number: { type: Number, required: true },
|
||||||
|
contact_Person_Name: { type: String, required: true },
|
||||||
city: { type: mongoose.Schema.ObjectId, ref: "City" },
|
city: { type: mongoose.Schema.ObjectId, ref: "City" },
|
||||||
|
|
||||||
|
|
||||||
products: [
|
products: [
|
||||||
{
|
{
|
||||||
type: mongoose.Schema.ObjectId,
|
type: mongoose.Schema.ObjectId,
|
||||||
|
@ -68,13 +68,16 @@ const getTempleById = async (req, res) => {
|
|||||||
const getTempleByIdPopulated = async (req, res) => {
|
const getTempleByIdPopulated = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const entity = await Temple.findById(req.params.id).populate({
|
const entity = await Temple.findById(req.params.id).populate({
|
||||||
// path: "grades sections houses",
|
path: "city",
|
||||||
sort: "name",
|
select: "city_name state -_id",
|
||||||
|
populate: {
|
||||||
|
path: "state",
|
||||||
|
select: "state_name state_code -_id",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const newId = new mongoose.Types.ObjectId();
|
return res.status(200).json({ status: "OK", data: entity });
|
||||||
return res.status(200).json({ status: "OK", data: entity, _id: newId });
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res.status(500).json({ message: "Unable to get menu items." });
|
return res.status(500).json({ message: "Unable to get franchiee ." });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -196,89 +199,7 @@ const findTempleByURL = async (req, res) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// const getTempleProductsForChild = async (req, res) => {
|
|
||||||
// try {
|
|
||||||
// const Temple = await Temple.findById(req.parent.Temple);
|
|
||||||
// if (!Temple?.option)
|
|
||||||
// return res.status(400).json({ message: "No option selected by Temple!" });
|
|
||||||
|
|
||||||
// const child = await Student.findById(req.params.id);
|
|
||||||
// if (!child?._id)
|
|
||||||
// return res.status(400).json({ message: "Child not found!" });
|
|
||||||
|
|
||||||
// if (Temple.option === "group") {
|
|
||||||
// const groups = await Group.find({
|
|
||||||
// Temple: req.parent.Temple,
|
|
||||||
// gender: child.gender,
|
|
||||||
// grades: { $in: child.grade },
|
|
||||||
// house: child.house,
|
|
||||||
// })
|
|
||||||
// .populate({
|
|
||||||
// path: "grades house",
|
|
||||||
// select: "name",
|
|
||||||
// })
|
|
||||||
// .populate({
|
|
||||||
// path: "products",
|
|
||||||
// select: "-createdAt -updatedAt",
|
|
||||||
// populate: {
|
|
||||||
// path: "images category variants",
|
|
||||||
// select: "url name size weight price tax",
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// return res.status(200).json({
|
|
||||||
// status: "OK",
|
|
||||||
// Temple_name: Temple.name,
|
|
||||||
// option: "group",
|
|
||||||
// data: groups,
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// const bundles = await Bundle.find({
|
|
||||||
// Temple: req.parent.Temple,
|
|
||||||
// gender: child.gender,
|
|
||||||
// grades: { $in: child.grade },
|
|
||||||
// house: child.house,
|
|
||||||
// })
|
|
||||||
// .populate({
|
|
||||||
// path: "grades house",
|
|
||||||
// select: "name",
|
|
||||||
// })
|
|
||||||
// .populate({
|
|
||||||
// path: "products.product",
|
|
||||||
// select: "-createdAt -updatedAt",
|
|
||||||
// populate: {
|
|
||||||
// path: "images category variants",
|
|
||||||
// select: "url name size weight price tax",
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// return res.status(200).json({
|
|
||||||
// status: "OK",
|
|
||||||
// Temple_name: Temple.name,
|
|
||||||
// option: "bundle",
|
|
||||||
// data: bundles,
|
|
||||||
// });
|
|
||||||
// } catch (error) {
|
|
||||||
// return res.status(500).json({ message: "Something went wrong!" });
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// const getTempleGradesAndHousesByParent = async (req, res) => {
|
|
||||||
// try {
|
|
||||||
// const Temple = await Temple.findById(req.parent.Temple).populate({
|
|
||||||
// path: "grades houses sections",
|
|
||||||
// select: "name",
|
|
||||||
// sort: "name",
|
|
||||||
// });
|
|
||||||
// return res.status(200).json({
|
|
||||||
// status: "ok",
|
|
||||||
// Temple_name: Temple.name,
|
|
||||||
// grades: Temple.grades,
|
|
||||||
// houses: Temple.houses,
|
|
||||||
// sections: Temple?.sections || [],
|
|
||||||
// });
|
|
||||||
// } catch (error) {
|
|
||||||
// return res.status(500).json({ message: "Something went wrong!" });
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
addTemple,
|
addTemple,
|
||||||
|
Loading…
Reference in New Issue
Block a user