aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/controller/transaction.ts
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2025-04-28 11:49:23 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2025-04-28 11:49:23 +0530
commitc3249a95bab905fa272a953133a643b49bdff557 (patch)
tree977ecd8b6bc87493e7a97df6225cc161585694a0 /src/controller/transaction.ts
parentb5f78bf3049c181b47d8692b728d7087c4fad51d (diff)
Added route to GET single transaction by idHEADmaster
Diffstat (limited to 'src/controller/transaction.ts')
-rw-r--r--src/controller/transaction.ts19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/controller/transaction.ts b/src/controller/transaction.ts
index 6c818d6..9d4d6da 100644
--- a/src/controller/transaction.ts
+++ b/src/controller/transaction.ts
@@ -16,7 +16,7 @@
*/
import { Request, Response } from "express";
-import { create, read, del } from "../service/transaction";
+import { create, read, readOne, del } from "../service/transaction";
const addNew = async (req: Request, res: Response) => {
try {
@@ -40,6 +40,22 @@ const get = async (req: Request, res: Response) => {
}
}
+const getOne = async (req: Request, res: Response) => {
+ try {
+ // @ts-ignore
+ const transaction = await readOne(req.userId, parseInt(req.params.transactionId)); // TODO: handle non int value passed (bad req)
+ res.status(200).json({ transaction: transaction });
+ } catch(error) {
+ // @ts-ignore
+ if (error.message == "forbidden") {
+ res.status(403).json({ error: "You are not allowed to view this transaction." });
+ } else {
+ res.status(500).json({ error: "Internal Server Error" });
+ console.error(error);
+ }
+ }
+}
+
const remove = async (req: Request, res: Response) => {
try {
// @ts-ignore
@@ -65,5 +81,6 @@ const remove = async (req: Request, res: Response) => {
export {
addNew,
get,
+ getOne,
remove
}