diff options
Diffstat (limited to 'src/controller/transaction.ts')
-rw-r--r-- | src/controller/transaction.ts | 22 |
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; + } } } |