mirror of
https://github.com/spliit-app/spliit.git
synced 2026-02-25 08:56:13 +01:00
Attach documents to expenses (#64)
* Upload documents to receipts * Improve documents * Make the feature opt-in * Fix file name issue
This commit is contained in:
committed by
GitHub
parent
11d2e298e8
commit
d43e731fe1
@@ -62,6 +62,16 @@ export async function createExpense(
|
||||
},
|
||||
},
|
||||
isReimbursement: expenseFormValues.isReimbursement,
|
||||
documents: {
|
||||
createMany: {
|
||||
data: expenseFormValues.documents.map((doc) => ({
|
||||
id: randomId(),
|
||||
url: doc.url,
|
||||
width: doc.width,
|
||||
height: doc.height,
|
||||
})),
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -159,6 +169,22 @@ export async function updateExpense(
|
||||
),
|
||||
},
|
||||
isReimbursement: expenseFormValues.isReimbursement,
|
||||
documents: {
|
||||
connectOrCreate: expenseFormValues.documents.map((doc) => ({
|
||||
create: doc,
|
||||
where: { id: doc.id },
|
||||
})),
|
||||
deleteMany: existingExpense.documents
|
||||
.filter(
|
||||
(existingDoc) =>
|
||||
!expenseFormValues.documents.some(
|
||||
(doc) => doc.id === existingDoc.id,
|
||||
),
|
||||
)
|
||||
.map((doc) => ({
|
||||
id: doc.id,
|
||||
})),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -231,6 +257,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, category: true },
|
||||
include: { paidBy: true, paidFor: true, category: true, documents: true },
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user