Files
spliit/src/trpc/routers/groups/expenses/list.procedure.ts
Sebastien Castiel c1c75fa260 Q: Why do mountain climbers rope themselves together?
A:	To prevent the sensible ones from going home.
2024-10-25 15:02:31 -04:00

30 lines
847 B
TypeScript

import { z } from 'zod'
import { getGroupExpenses } from '../../../../lib/api'
import { baseProcedure } from '../../../init'
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,
}
})