aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/service/transaction.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/transaction.ts')
-rw-r--r--src/service/transaction.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/service/transaction.ts b/src/service/transaction.ts
index 8f1c99d..c3a2408 100644
--- a/src/service/transaction.ts
+++ b/src/service/transaction.ts
@@ -42,6 +42,21 @@ const read = async (userId: Number, type: String) => {
})
}
+const readOne = async (userId: Number, id: Number) => {
+ const transaction = await prisma.transaction.findUnique({
+ // @ts-ignore
+ where: { id: id },
+ })
+
+ // NOTE: this gon change a bit when there are also collaborators
+ // @ts-ignore
+ if (transaction.userId !== userId) {
+ throw new Error("forbidden")
+ }
+
+ return transaction
+}
+
// TODO: ig collaborated transactions would need more logic
const del = async (userId: Number, transactionId: String) => {
const t = await prisma.transaction.findUnique({
@@ -66,5 +81,6 @@ const del = async (userId: Number, transactionId: String) => {
export {
create,
read,
+ readOne,
del
}