mirror of
https://github.com/spliit-app/spliit.git
synced 2026-03-07 20:59:05 +01:00
Use tRPC for expense form (#251)
This commit is contained in:
committed by
GitHub
parent
2281316d58
commit
21d0c02687
23
src/trpc/routers/groups/expenses/create.procedure.ts
Normal file
23
src/trpc/routers/groups/expenses/create.procedure.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { createExpense } from '@/lib/api'
|
||||
import { expenseFormSchema } from '@/lib/schemas'
|
||||
import { baseProcedure } from '@/trpc/init'
|
||||
import { z } from 'zod'
|
||||
|
||||
export const createGroupExpenseProcedure = baseProcedure
|
||||
.input(
|
||||
z.object({
|
||||
groupId: z.string().min(1),
|
||||
expenseFormValues: expenseFormSchema,
|
||||
participantId: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.mutation(
|
||||
async ({ input: { groupId, expenseFormValues, participantId } }) => {
|
||||
const expense = await createExpense(
|
||||
expenseFormValues,
|
||||
groupId,
|
||||
participantId,
|
||||
)
|
||||
return { expenseId: expense.id }
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user