mirror of
https://github.com/spliit-app/spliit.git
synced 2026-03-08 21:29:05 +01:00
Add tRPC, use it for group expenses, balances and information page (#246)
* Add tRPC, use it for group expense list * Use tRPC for balances * Use tRPC in group information + better loading states
This commit is contained in:
committed by
GitHub
parent
727803ea5c
commit
66e15e419e
29
src/trpc/routers/groups/expenses/list.procedure.ts
Normal file
29
src/trpc/routers/groups/expenses/list.procedure.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { getGroupExpenses } from '@/lib/api'
|
||||
import { baseProcedure } from '@/trpc/init'
|
||||
import { z } from 'zod'
|
||||
|
||||
export const listGroupExpensesProcedure = baseProcedure
|
||||
.input(
|
||||
z.object({
|
||||
groupId: z.string().min(1),
|
||||
cursor: z.number().optional(),
|
||||
limit: z.number().optional(),
|
||||
filter: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.query(async ({ input: { groupId, cursor = 0, limit = 10, filter } }) => {
|
||||
const expenses = await getGroupExpenses(groupId, {
|
||||
offset: cursor,
|
||||
length: limit + 1,
|
||||
filter,
|
||||
})
|
||||
return {
|
||||
expenses: expenses.slice(0, limit).map((expense) => ({
|
||||
...expense,
|
||||
createdAt: new Date(expense.createdAt),
|
||||
expenseDate: new Date(expense.expenseDate),
|
||||
})),
|
||||
hasMore: !!expenses[limit],
|
||||
nextCursor: cursor + limit,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user