order Api: implement the searching system

This commit is contained in:
2026-04-17 01:59:58 +06:00
parent 475bc6f49e
commit 164951321b
4 changed files with 69 additions and 11 deletions
+1 -1
View File
@@ -38,7 +38,7 @@
"@types/express": "^5.0.3", "@types/express": "^5.0.3",
"@types/jsonwebtoken": "^9.0.10", "@types/jsonwebtoken": "^9.0.10",
"@types/multer": "^2.0.0", "@types/multer": "^2.0.0",
"@types/node": "^24.10.9", "@types/node": "^24.12.2",
"@types/nodemailer": "^7.0.2", "@types/nodemailer": "^7.0.2",
"@types/pg": "^8.20.0", "@types/pg": "^8.20.0",
"@types/swagger-jsdoc": "^6.0.4", "@types/swagger-jsdoc": "^6.0.4",
+50 -1
View File
@@ -6,7 +6,55 @@ import { orderEmailQueue } from "../../queues/email/order/order.email.queue";
const get_all_order_from_db = async (req: Request) => { const get_all_order_from_db = async (req: Request) => {
// define your own login here // 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; return result;
}; };
@@ -19,6 +67,7 @@ const get_single_order_from_db = async (req: Request) => {
const create_order_into_db = async (req: Request) => { const create_order_into_db = async (req: Request) => {
const payload = req?.body; const payload = req?.body;
console.log(payload)
payload.status = "INITIATED"; payload.status = "INITIATED";
payload.paymentType = "COD" payload.paymentType = "COD"
+18
View File
@@ -45,6 +45,24 @@ export const orderSwaggerDocs = {
required: false, required: false,
schema: { type: "number" }, 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: { responses: {
200: { description: "order fetched successfully" }, 200: { description: "order fetched successfully" },
@@ -13,15 +13,6 @@ const create_order = z.object({
customerNote: z.string().optional() customerNote: z.string().optional()
}); });
const update_order = z.object({ 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() status: z.string().optional()
}); });