Bug/db-update:Fixed the db update related issues and also update the filter system

This commit is contained in:
2026-06-17 23:09:05 +06:00
parent 7bf4bc93f1
commit 3ce71be929
3 changed files with 22 additions and 50 deletions
+20 -48
View File
@@ -19,54 +19,30 @@ const get_all_order_from_db = async (req: Request) => {
const status = (req.query.status as string) || undefined; const status = (req.query.status as string) || undefined;
const { page, limit, skip, sortBy, sortOrder } = paginationHelper(req.query); const { page, limit, skip, sortBy, sortOrder } = paginationHelper(req.query);
const andCondition = [] as any[]; const andCondition = {} as any;
if (search) { if (search) {
andCondition.push({ andCondition.productName = {
OR: [ contains: search,
{ mode: "insensitive",
productName: { };
contains: search,
mode: "insensitive",
},
},
],
});
} }
if (customerName) { if (customerName) {
andCondition.push({ andCondition.customerName = {
OR: [ contains: customerName,
{ mode: "insensitive",
customerName: { };
contains: customerName,
mode: "insensitive",
},
},
],
});
} }
if (productName) { if (productName) {
andCondition.push({ andCondition.productName = {
OR: [ contains: productName,
{ mode: "insensitive",
productName: { };
contains: productName,
mode: "insensitive",
},
},
],
});
} }
if (status) { if (status) {
andCondition.push({ andCondition.status = {
OR: [ contains: status,
{ mode: "insensitive",
status: { };
contains: status,
mode: "insensitive",
},
},
],
});
} }
// for date filter // for date filter
@@ -82,17 +58,13 @@ const get_all_order_from_db = async (req: Request) => {
dateFilter.lte = end; dateFilter.lte = end;
} }
if (Object.keys(dateFilter).length > 0) { if (Object.keys(dateFilter).length > 0) {
andCondition.push({ andCondition.createdAt = dateFilter;
createdAt: dateFilter,
});
} }
const getAllOrders = await prisma.order.findMany({ const getAllOrders = await prisma.order.findMany({
take: limit, take: limit,
skip, skip,
where: { where: andCondition,
AND: andCondition,
},
select: { select: {
id: true, id: true,
customerName: 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 create_order_into_db = async (req: Request) => {
const payload = req?.body; const payload = req?.body;
payload.status = "INITIATED"; payload.status = "INITIATED";
payload.paymentType = "COD"; payload.paymentType = "COD";
+1 -1
View File
@@ -121,7 +121,7 @@ export const orderSwaggerDocs = {
patch: { patch: {
tags: ["order"], tags: ["order"],
summary: "Update order -(Admin route)", summary: "Update order -(Admin route)",
description: "", description: "The status can be updated to any of the following values : INITIATED,CONFIRMED,ONGOING,DELIVERED,CANCELLED",
parameters: [ parameters: [
{ {
name: "id", name: "id",
+1 -1
View File
@@ -13,7 +13,7 @@ const create_order = z.object({
customerNote: z.string().optional() customerNote: z.string().optional()
}); });
const update_order = z.object({ const update_order = z.object({
status: z.string().optional() status: z.enum(["INITIATED","CONFIRMED","ONGOING","DELIVERED","CANCELLED"]).optional()
}); });
export const order_validations = { export const order_validations = {