aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/controller/transaction.ts
diff options
context:
space:
mode:
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
}