mirror of
https://github.com/spliit-app/spliit.git
synced 2026-03-02 11:26:11 +01:00
30 lines
847 B
TypeScript
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,
|
|
}
|
|
})
|