feat(expenses): enhance expenses management with filtering and search capabilities
This commit is contained in:
@@ -88,12 +88,20 @@ export async function listExpenses(params: {
|
||||
status?: string;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
periodicExpenseId?: number;
|
||||
search?: string;
|
||||
}) {
|
||||
const { status, page = 1, pageSize = 10 } = params;
|
||||
const { status, page = 1, pageSize = 10, periodicExpenseId, search } = params;
|
||||
const where: Record<string, unknown> = {};
|
||||
if (status === "PENDING" || status === "PAYED") {
|
||||
where.status = status;
|
||||
}
|
||||
if (periodicExpenseId !== undefined) {
|
||||
where.periodicExpenseId = periodicExpenseId;
|
||||
}
|
||||
if (search) {
|
||||
where.description = { contains: search, mode: "insensitive" };
|
||||
}
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.expense.findMany({
|
||||
where,
|
||||
|
||||
@@ -5,6 +5,14 @@ export async function listExpensesHandler(c: Context) {
|
||||
const status = c.req.query("status");
|
||||
const page = parseInt(c.req.query("page") ?? "1", 10);
|
||||
const pageSize = parseInt(c.req.query("pageSize") ?? "10", 10);
|
||||
const result = await listExpenses({ status, page, pageSize });
|
||||
const periodicExpenseId = c.req.query("periodicExpenseId");
|
||||
const search = c.req.query("search");
|
||||
const result = await listExpenses({
|
||||
status,
|
||||
page,
|
||||
pageSize,
|
||||
periodicExpenseId: periodicExpenseId ? parseInt(periodicExpenseId, 10) : undefined,
|
||||
search: search || undefined,
|
||||
});
|
||||
return c.json(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user