order Api: implement the searching system
This commit is contained in:
@@ -6,7 +6,55 @@ import { orderEmailQueue } from "../../queues/email/order/order.email.queue";
|
||||
|
||||
const get_all_order_from_db = async (req: Request) => {
|
||||
// define your own login here
|
||||
const result = await prisma.order.findMany();
|
||||
const search=req.query.search as string
|
||||
const customerName=req.query.customerName as string
|
||||
const productName=req.query.productName as string
|
||||
console.log(productName)
|
||||
const andCondition=[] as any[]
|
||||
if(search){
|
||||
andCondition.push({
|
||||
OR:[
|
||||
{
|
||||
productName:{
|
||||
contains:search,
|
||||
mode:"insensitive"
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
if(customerName){
|
||||
andCondition.push({
|
||||
OR:[
|
||||
{
|
||||
customerName:{
|
||||
contains:customerName,
|
||||
mode:"insensitive"
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
if(productName){
|
||||
andCondition.push({
|
||||
OR:[
|
||||
{
|
||||
productName:{
|
||||
contains:productName,
|
||||
mode:"insensitive"
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
console.log(search)
|
||||
|
||||
const result = await prisma.order.findMany({
|
||||
where:{
|
||||
AND:andCondition
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -19,6 +67,7 @@ const get_single_order_from_db = async (req: Request) => {
|
||||
|
||||
const create_order_into_db = async (req: Request) => {
|
||||
const payload = req?.body;
|
||||
console.log(payload)
|
||||
payload.status = "INITIATED";
|
||||
payload.paymentType = "COD"
|
||||
|
||||
|
||||
@@ -45,6 +45,24 @@ export const orderSwaggerDocs = {
|
||||
required: false,
|
||||
schema: { type: "number" },
|
||||
},
|
||||
{
|
||||
name: "search",
|
||||
in: "query",
|
||||
required: false,
|
||||
schema: { type: "string" },
|
||||
},
|
||||
{
|
||||
name: "customerName",
|
||||
in: "query",
|
||||
required: false,
|
||||
schema: { type: "string" },
|
||||
},
|
||||
{
|
||||
name: "productName",
|
||||
in: "query",
|
||||
required: false,
|
||||
schema: { type: "string" },
|
||||
},
|
||||
],
|
||||
responses: {
|
||||
200: { description: "order fetched successfully" },
|
||||
|
||||
@@ -13,15 +13,6 @@ const create_order = z.object({
|
||||
customerNote: z.string().optional()
|
||||
});
|
||||
const update_order = z.object({
|
||||
shopAccountId: z.string().optional(),
|
||||
productPrice: z.number().optional(),
|
||||
productQuantity: z.number().optional(),
|
||||
productName: z.string().optional(),
|
||||
customerName: z.string().optional(),
|
||||
customerPhone: z.string().optional(),
|
||||
customerEmail: z.string().optional(),
|
||||
customerAddress: z.string().optional(),
|
||||
customerNote: z.string().optional(),
|
||||
status: z.string().optional()
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user