aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/api.ts
diff options
context:
space:
mode:
authorSebastien Castiel <sebastien@castiel.me>2024-01-28 18:51:29 -0500
committerGitHub <noreply@github.com>2024-01-28 18:51:29 -0500
commitd43e731fe191d7e35d96847fe095c94555dd8ca6 (patch)
treeb8bc3f99770a47ec0343f642ca04e727f7abd716 /src/lib/api.ts
parent11d2e298e8cc5cac07aa2c60e194bf4460cefb21 (diff)
Attach documents to expenses (#64)
* Upload documents to receipts * Improve documents * Make the feature opt-in * Fix file name issue
Diffstat (limited to 'src/lib/api.ts')
-rw-r--r--src/lib/api.ts28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/lib/api.ts b/src/lib/api.ts
index c27e584..dfa9651 100644
--- a/src/lib/api.ts
+++ b/src/lib/api.ts
@@ -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 },
})
}