diff --git a/src/app/modules/order/order.service.ts b/src/app/modules/order/order.service.ts index 864b9ed..8be34f1 100644 --- a/src/app/modules/order/order.service.ts +++ b/src/app/modules/order/order.service.ts @@ -19,54 +19,30 @@ const get_all_order_from_db = async (req: Request) => { const status = (req.query.status as string) || undefined; const { page, limit, skip, sortBy, sortOrder } = paginationHelper(req.query); - const andCondition = [] as any[]; + const andCondition = {} as any; if (search) { - andCondition.push({ - OR: [ - { - productName: { - contains: search, - mode: "insensitive", - }, - }, - ], - }); + andCondition.productName = { + contains: search, + mode: "insensitive", + }; } if (customerName) { - andCondition.push({ - OR: [ - { - customerName: { - contains: customerName, - mode: "insensitive", - }, - }, - ], - }); + andCondition.customerName = { + contains: customerName, + mode: "insensitive", + }; } if (productName) { - andCondition.push({ - OR: [ - { - productName: { - contains: productName, - mode: "insensitive", - }, - }, - ], - }); + andCondition.productName = { + contains: productName, + mode: "insensitive", + }; } if (status) { - andCondition.push({ - OR: [ - { - status: { - contains: status, - mode: "insensitive", - }, - }, - ], - }); + andCondition.status = { + contains: status, + mode: "insensitive", + }; } // for date filter @@ -82,17 +58,13 @@ const get_all_order_from_db = async (req: Request) => { dateFilter.lte = end; } if (Object.keys(dateFilter).length > 0) { - andCondition.push({ - createdAt: dateFilter, - }); + andCondition.createdAt = dateFilter; } const getAllOrders = await prisma.order.findMany({ take: limit, skip, - where: { - AND: andCondition, - }, + where: andCondition, select: { id: true, customerName: true, @@ -130,7 +102,7 @@ const get_single_order_from_db = async (req: Request) => { const create_order_into_db = async (req: Request) => { const payload = req?.body; - + 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 f4d705c..b281705 100644 --- a/src/app/modules/order/order.swagger.ts +++ b/src/app/modules/order/order.swagger.ts @@ -121,7 +121,7 @@ export const orderSwaggerDocs = { patch: { tags: ["order"], summary: "Update order -(Admin route)", - description: "", + description: "The status can be updated to any of the following values : INITIATED,CONFIRMED,ONGOING,DELIVERED,CANCELLED", parameters: [ { name: "id", diff --git a/src/app/modules/order/order.validation.ts b/src/app/modules/order/order.validation.ts index e3a08aa..9b23609 100644 --- a/src/app/modules/order/order.validation.ts +++ b/src/app/modules/order/order.validation.ts @@ -13,7 +13,7 @@ const create_order = z.object({ customerNote: z.string().optional() }); const update_order = z.object({ - status: z.string().optional() + status: z.enum(["INITIATED","CONFIRMED","ONGOING","DELIVERED","CANCELLED"]).optional() }); export const order_validations = {