mirror of
https://github.com/spliit-app/spliit.git
synced 2026-03-07 20:59:05 +01:00
Use tRPC in other group pages (#249)
* Use tRPC in group edition + group layout * Use tRPC in group modals * Use tRPC in group stats * Use tRPC in group activity
This commit is contained in:
committed by
GitHub
parent
66e15e419e
commit
210c12b7ef
35
src/trpc/routers/groups/stats/get.procedure.ts
Normal file
35
src/trpc/routers/groups/stats/get.procedure.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { getGroupExpenses } from '@/lib/api'
|
||||
import {
|
||||
getTotalActiveUserPaidFor,
|
||||
getTotalActiveUserShare,
|
||||
getTotalGroupSpending,
|
||||
} from '@/lib/totals'
|
||||
import { baseProcedure } from '@/trpc/init'
|
||||
import { z } from 'zod'
|
||||
|
||||
export const getGroupStatsProcedure = baseProcedure
|
||||
.input(
|
||||
z.object({
|
||||
groupId: z.string().min(1),
|
||||
participantId: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.query(async ({ input: { groupId, participantId } }) => {
|
||||
const expenses = await getGroupExpenses(groupId)
|
||||
const totalGroupSpendings = getTotalGroupSpending(expenses)
|
||||
|
||||
const totalParticipantSpendings =
|
||||
participantId !== undefined
|
||||
? getTotalActiveUserPaidFor(participantId, expenses)
|
||||
: undefined
|
||||
const totalParticipantShare =
|
||||
participantId !== undefined
|
||||
? getTotalActiveUserShare(participantId, expenses)
|
||||
: undefined
|
||||
|
||||
return {
|
||||
totalGroupSpendings,
|
||||
totalParticipantSpendings,
|
||||
totalParticipantShare,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user