aboutsummaryrefslogtreecommitdiff
path: root/src/controller/transaction.ts
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2025-04-15 13:01:38 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2025-04-15 13:01:38 +0530
commit9c911e79c18d09224b90546ef29c2e9986e4cc0c (patch)
tree5de085d2c61a8e606caeb787dd391b3de5477fc4 /src/controller/transaction.ts
parent549f75c9e271ca9b8b8f919ee996526b31e659a8 (diff)
Added functionality to delete a transaction
Diffstat (limited to 'src/controller/transaction.ts')
-rw-r--r--src/controller/transaction.ts22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/controller/transaction.ts b/src/controller/transaction.ts
index b5fcf99..6c818d6 100644
--- a/src/controller/transaction.ts
+++ b/src/controller/transaction.ts
@@ -16,7 +16,7 @@
*/
import { Request, Response } from "express";
-import { create, read } from "../service/transaction";
+import { create, read, del } from "../service/transaction";
const addNew = async (req: Request, res: Response) => {
try {
@@ -42,11 +42,23 @@ const get = async (req: Request, res: Response) => {
const remove = async (req: Request, res: Response) => {
try {
- // TODO: check ownership before deletion
- res.status(200).json({ "message": "work in progress" })
+ // @ts-ignore
+ await del(req.userId, req.body.id)
+ res.status(200).json({ "message": "success" })
} catch(error) {
- res.status(500).json({ error: "Internal Server Error" });
- console.error(error);
+ // @ts-ignore
+ switch (error.message) {
+ case "403":
+ res.status(403).json({ error: "Not Authorized To Do This Task" });
+ break;
+ case "404":
+ res.status(404).json({ error: "Not Found" });
+ break;
+ default:
+ res.status(500).json({ error: "Internal Server Error" });
+ console.error(error);
+ break;
+ }
}
}