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
+11 -39
View File
@@ -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: {
andCondition.productName = {
contains: search,
mode: "insensitive",
},
},
],
});
};
}
if (customerName) {
andCondition.push({
OR: [
{
customerName: {
andCondition.customerName = {
contains: customerName,
mode: "insensitive",
},
},
],
});
};
}
if (productName) {
andCondition.push({
OR: [
{
productName: {
andCondition.productName = {
contains: productName,
mode: "insensitive",
},
},
],
});
};
}
if (status) {
andCondition.push({
OR: [
{
status: {
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,
+1 -1
View File
@@ -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",
+1 -1
View File
@@ -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 = {