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({
|
const order = await Order.find().populate({
|
||||||
path: "user",
|
path: "user",
|
||||||
select: "name -_id",
|
select: "name -_id",
|
||||||
});
|
}).sort({ createdAt: -1 });
|
||||||
if (order) {
|
if (order) {
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
success: true,
|
success: true,
|
||||||
@ -69,3 +69,32 @@ export const getAllOrder = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
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,
|
required: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
shippingInfo: [{
|
shippingInfo: {
|
||||||
name: { type: String, required: true, },
|
name: { type: String, required: true, },
|
||||||
address: {
|
address: {
|
||||||
type: String,
|
type: String,
|
||||||
@ -44,7 +44,7 @@ const orderSchema = new mongoose.Schema(
|
|||||||
type: mongoose.Schema.ObjectId,
|
type: mongoose.Schema.ObjectId,
|
||||||
ref: "Temple",
|
ref: "Temple",
|
||||||
},
|
},
|
||||||
}],
|
},
|
||||||
orderItems: [
|
orderItems: [
|
||||||
{
|
{
|
||||||
name: {
|
name: {
|
||||||
@ -64,6 +64,24 @@ const orderSchema = new mongoose.Schema(
|
|||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
taxRate: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
|
},
|
||||||
|
|
||||||
|
PriceWithTax: {
|
||||||
|
type: Number,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
taxName: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
taxId: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
},
|
||||||
|
|
||||||
product: {
|
product: {
|
||||||
type: mongoose.Schema.ObjectId,
|
type: mongoose.Schema.ObjectId,
|
||||||
ref: "Product",
|
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 { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
router.route("/order/create").post(isAuthenticatedUser, authorizeRoles("admin"), createOrder)
|
router.route("/order/create").post(isAuthenticatedUser, authorizeRoles("admin"), createOrder)
|
||||||
router.route("/order/getAll").get(isAuthenticatedUser, authorizeRoles("admin"), getAllOrder)
|
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)
|
// 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({
|
const data = await Product.create({
|
||||||
...req.body,
|
...req.body,
|
||||||
|
|
||||||
image: {
|
image: {
|
||||||
public_id: myCloud.public_id,
|
public_id: myCloud.public_id,
|
||||||
url: myCloud.secure_url,
|
url: myCloud.secure_url,
|
||||||
@ -99,11 +100,16 @@ export const updateProduct = async (req, res) => {
|
|||||||
name: req.body.name,
|
name: req.body.name,
|
||||||
description: req.body.description,
|
description: req.body.description,
|
||||||
base_Price: req.body.base_Price,
|
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: 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: req.body.price_Level_3,
|
||||||
};
|
price_Level_3_With_Tax: req.body.price_Level_3_With_Tax,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (req.files) {
|
if (req.files) {
|
||||||
const image_file = req.files.image;
|
const image_file = req.files.image;
|
||||||
const getProduct = await Product.findById(req.params.id);
|
const getProduct = await Product.findById(req.params.id);
|
||||||
|
@ -18,18 +18,40 @@ const productSchema = new Schema({
|
|||||||
required: [true, "Please Enter product Price"],
|
required: [true, "Please Enter product Price"],
|
||||||
maxLength: [8, "Price cannot exceed 8 characters"],
|
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: {
|
price_Level_2: {
|
||||||
type: Number,
|
type: Number,
|
||||||
required: true,
|
required: true,
|
||||||
|
|
||||||
maxLength: [8, "price leval2 cannot exceed 8 characters"],
|
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: {
|
price_Level_3: {
|
||||||
type: Number,
|
type: Number,
|
||||||
required: true,
|
required: true,
|
||||||
|
|
||||||
maxLength: [8, "price leval3 cannot exceed 8 characters"],
|
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:
|
||||||
{
|
{
|
||||||
|
@ -18,6 +18,7 @@ const TempleSchema = new Schema(
|
|||||||
ref: "Product",
|
ref: "Product",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
price_Lable: { type: String, default: "" },
|
||||||
url: { type: String, default: "" },
|
url: { type: String, default: "" },
|
||||||
short_url: { type: String, default: "" },
|
short_url: { type: String, default: "" },
|
||||||
banner: { type: Object, default: { url: "", public_id: "" } },
|
banner: { type: Object, default: { url: "", public_id: "" } },
|
||||||
|
Loading…
Reference in New Issue
Block a user