feat(orders): month/year filter on both order lists + fix received-orders search

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
BOHA
2026-06-09 13:22:39 +02:00
parent 2b7b480144
commit 3b48bd0523
8 changed files with 186 additions and 5 deletions

View File

@@ -45,6 +45,8 @@ interface ListIssuedOrdersParams {
search?: string;
status?: string;
customer_id?: number;
month?: number;
year?: number;
}
const VALID_TRANSITIONS: Record<string, string[]> = {
@@ -92,8 +94,18 @@ export function computeIssuedOrderTotals(
}
export async function listIssuedOrders(params: ListIssuedOrdersParams) {
const { page, limit, skip, sort, order, search, status, customer_id } =
params;
const {
page,
limit,
skip,
sort,
order,
search,
status,
customer_id,
month,
year,
} = params;
const sortField = ALLOWED_SORT_FIELDS.includes(sort) ? sort : "id";
const where: Record<string, unknown> = {};
@@ -106,6 +118,11 @@ export async function listIssuedOrders(params: ListIssuedOrdersParams) {
{ customers: { company_id: { contains: search } } },
];
}
if (month && year) {
const from = new Date(year, month - 1, 1);
const to = new Date(year, month, 1);
where.order_date = { gte: from, lt: to };
}
// Normalize the direction so an unexpected value can't reach Prisma at runtime.
const dir: "asc" | "desc" = order === "asc" ? "asc" : "desc";