mirror of
https://github.com/spliit-app/spliit.git
synced 2025-12-06 09:29:39 +01:00
Assign categories to expenses (#28)
* add expense categories * set category to Payment for reimbursements * Insert categories as part of the migration * Display category groups --------- Co-authored-by: Sebastien Castiel <sebastien@castiel.me>
This commit is contained in:
@@ -48,6 +48,7 @@ export async function createExpense(
|
||||
id: randomId(),
|
||||
groupId,
|
||||
expenseDate: expenseFormValues.expenseDate,
|
||||
categoryId: expenseFormValues.category,
|
||||
amount: expenseFormValues.amount,
|
||||
title: expenseFormValues.title,
|
||||
paidById: expenseFormValues.paidBy,
|
||||
@@ -124,6 +125,7 @@ export async function updateExpense(
|
||||
expenseDate: expenseFormValues.expenseDate,
|
||||
amount: expenseFormValues.amount,
|
||||
title: expenseFormValues.title,
|
||||
categoryId: expenseFormValues.category,
|
||||
paidById: expenseFormValues.paidBy,
|
||||
splitMode: expenseFormValues.splitMode,
|
||||
paidFor: {
|
||||
@@ -207,11 +209,16 @@ export async function getGroup(groupId: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function getCategories() {
|
||||
const prisma = await getPrisma()
|
||||
return prisma.category.findMany()
|
||||
}
|
||||
|
||||
export async function getGroupExpenses(groupId: string) {
|
||||
const prisma = await getPrisma()
|
||||
return prisma.expense.findMany({
|
||||
where: { groupId },
|
||||
include: { paidFor: { include: { participant: true } }, paidBy: true },
|
||||
include: { paidFor: { include: { participant: true } }, paidBy: true, category: true },
|
||||
orderBy: { expenseDate: 'desc' },
|
||||
})
|
||||
}
|
||||
@@ -220,6 +227,6 @@ export async function getExpense(groupId: string, expenseId: string) {
|
||||
const prisma = await getPrisma()
|
||||
return prisma.expense.findUnique({
|
||||
where: { id: expenseId },
|
||||
include: { paidBy: true, paidFor: true },
|
||||
include: { paidBy: true, paidFor: true, category: true },
|
||||
})
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ export const expenseFormSchema = z
|
||||
title: z
|
||||
.string({ required_error: 'Please enter a title.' })
|
||||
.min(2, 'Enter at least two characters.'),
|
||||
category: z.coerce.number().default(0),
|
||||
amount: z
|
||||
.union(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user