product and franchisee change
This commit is contained in:
parent
9de3c4bfed
commit
542815d95f
@ -53,7 +53,7 @@ export const getAllOrder = async (req, res) => {
|
||||
const order = await Order.find().populate({
|
||||
path: "user",
|
||||
select: "name -_id",
|
||||
});
|
||||
}).sort({ createdAt: -1 });
|
||||
if (order) {
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
@ -68,4 +68,33 @@ export const getAllOrder = async (req, res) => {
|
||||
res.status(500).json({ msg: error.message ? error.message : 'Something went Wrong' })
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
export const deleteOneOrder = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
if (!req.params.id) return res.status(400).json({ message: "please Provide Order Id" });
|
||||
const getOrder = await Order.findById(req.params.id);
|
||||
if (!getOrder) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
msg: "No Order Found!"
|
||||
});
|
||||
|
||||
}
|
||||
const order = await Order.findByIdAndDelete(req.params.id)
|
||||
|
||||
await order.remove();
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "Order Deleted Successfully!!",
|
||||
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).json({ msg: error.message ? error.message : 'Something went Wrong' })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@ const orderSchema = new mongoose.Schema(
|
||||
required: true,
|
||||
},
|
||||
|
||||
shippingInfo: [{
|
||||
shippingInfo: {
|
||||
name: { type: String, required: true, },
|
||||
address: {
|
||||
type: String,
|
||||
@ -44,7 +44,7 @@ const orderSchema = new mongoose.Schema(
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "Temple",
|
||||
},
|
||||
}],
|
||||
},
|
||||
orderItems: [
|
||||
{
|
||||
name: {
|
||||
@ -64,6 +64,24 @@ const orderSchema = new mongoose.Schema(
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
taxRate: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
|
||||
PriceWithTax: {
|
||||
type: Number,
|
||||
default: '',
|
||||
},
|
||||
taxName: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
taxId: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
|
||||
product: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "Product",
|
||||
|
@ -1,11 +1,14 @@
|
||||
import { createOrder, getAllOrder } from "./orderController.js";
|
||||
import { createOrder, deleteOneOrder, 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("/order/delete/:id").delete(isAuthenticatedUser, authorizeRoles("admin"), deleteOneOrder)
|
||||
|
||||
|
||||
|
||||
// router.route("/product/getAll/").get(getAllProduct)
|
||||
|
||||
export default router;
|
||||
export default router
|
@ -29,6 +29,7 @@ export const createProduct = async (req, res) => {
|
||||
|
||||
const data = await Product.create({
|
||||
...req.body,
|
||||
|
||||
image: {
|
||||
public_id: myCloud.public_id,
|
||||
url: myCloud.secure_url,
|
||||
@ -99,11 +100,16 @@ export const updateProduct = async (req, res) => {
|
||||
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,
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (req.files) {
|
||||
const image_file = req.files.image;
|
||||
const getProduct = await Product.findById(req.params.id);
|
||||
|
@ -18,18 +18,40 @@ const productSchema = new Schema({
|
||||
required: [true, "Please Enter product Price"],
|
||||
maxLength: [8, "Price cannot exceed 8 characters"],
|
||||
},
|
||||
base_Price_With_Tax: {
|
||||
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:
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ const TempleSchema = new Schema(
|
||||
ref: "Product",
|
||||
},
|
||||
],
|
||||
price_Lable: { type: String, default: "" },
|
||||
url: { type: String, default: "" },
|
||||
short_url: { type: String, default: "" },
|
||||
banner: { type: Object, default: { url: "", public_id: "" } },
|
||||
|
Loading…
Reference in New Issue
Block a user