Skip to content

Commit

Permalink
include page options when summing transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hbbb committed Jan 28, 2024
1 parent 111b28f commit c19b992
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions electron/main/models/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ export async function fetchTransactions({
})
}

const pageOptions = {
take: pageSize === Infinity ? undefined : pageSize,
skip: pageIndex === 0 ? 0 : pageIndex * pageSize,
orderBy: {
[sortColumn]: sort,
},
}

const [
results,
total,
Expand All @@ -52,18 +60,18 @@ export async function fetchTransactions({
},
] = await Promise.all([
prisma.transaction.findMany({
orderBy: {
[sortColumn]: sort,
},
take: pageSize === Infinity ? undefined : pageSize,
skip: pageIndex === 0 ? 0 : pageIndex * pageSize,
where,
include: {
account: true,
},
...pageOptions,
}),
prisma.transaction.count({ where }),
prisma.transaction.aggregate({ where, _sum: { amount: true } }),
prisma.transaction.aggregate({
where,
_sum: { amount: true },
...pageOptions,
}),
])

const pageCount = Math.ceil(total / pageSize)
Expand Down

0 comments on commit c19b992

Please sign in to comment.