From 164951321ba06184b80dd7f53ed58b9e62a39d67 Mon Sep 17 00:00:00 2001 From: Md Sharafat Hassain Binoy Date: Fri, 17 Apr 2026 01:59:58 +0600 Subject: [PATCH] order Api: implement the searching system --- package.json | 2 +- src/app/modules/order/order.service.ts | 51 ++++++++++++++++++++++- src/app/modules/order/order.swagger.ts | 18 ++++++++ src/app/modules/order/order.validation.ts | 9 ---- 4 files changed, 69 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index f4b3d6c..8d527f7 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@types/express": "^5.0.3", "@types/jsonwebtoken": "^9.0.10", "@types/multer": "^2.0.0", - "@types/node": "^24.10.9", + "@types/node": "^24.12.2", "@types/nodemailer": "^7.0.2", "@types/pg": "^8.20.0", "@types/swagger-jsdoc": "^6.0.4", diff --git a/src/app/modules/order/order.service.ts b/src/app/modules/order/order.service.ts index 371301b..c9c11b8 100644 --- a/src/app/modules/order/order.service.ts +++ b/src/app/modules/order/order.service.ts @@ -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" diff --git a/src/app/modules/order/order.swagger.ts b/src/app/modules/order/order.swagger.ts index f0e2f4d..103de00 100644 --- a/src/app/modules/order/order.swagger.ts +++ b/src/app/modules/order/order.swagger.ts @@ -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" }, diff --git a/src/app/modules/order/order.validation.ts b/src/app/modules/order/order.validation.ts index 114c4ff..e3a08aa 100644 --- a/src/app/modules/order/order.validation.ts +++ b/src/app/modules/order/order.validation.ts @@ -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() });