소스 검색

addititonal info about archived purchases

kunickyd 3 년 전
부모
커밋
8f0919297a
1개의 변경된 파일27개의 추가작업 그리고 7개의 파일을 삭제
  1. 27 7
      app.ts

+ 27 - 7
app.ts

@@ -44,10 +44,10 @@ app.get("/", (req, res) => {
 });
 
 app.get("/transfers/:userId", async (req, res, next) => {
-    let db = await getDbConnection();
+    let db = getDbConnection();
 
     db.all(
-        "SELECT hash " +
+        "SELECT * " +
         "FROM transfers " +
         "WHERE user=? " +
         "ORDER BY id DESC " +
@@ -83,12 +83,29 @@ app.post("/transfer", async (req, res, next) => {
             throw Error(JSON.stringify({ error: { name: "Error, request body has no \"user\" property!" } }));
         }
 
-        let db = await getDbConnection();
+        if (!req.body.extent) {
+            res.status(400);
+            throw Error(JSON.stringify({ error: { name: "Error, request body has no \"extent\" property!" } }));
+        }
+
+        if (!req.body.amount) {
+            res.status(400);
+            throw Error(JSON.stringify({ error: { name: "Error, request body has no \"amount\" property!" } }));
+        }
+
+        if (!req.body.timestamp) {
+            res.status(400);
+            throw Error(JSON.stringify({ error: { name: "Error, request body has no \"timestamp\" property!" } }));
+        }
+
+
+
+        let db = getDbConnection();
 
         db.run(
-            "INSERT INTO transfers (hash, user)" +
-            "VALUES (?, ?);",
-            [req.body.txHash, req.body.user],
+            "INSERT INTO transfers (hash, user, extent, amount, timestamp)" +
+            "VALUES (?, ?, ?, ?, ?);",
+            [req.body.txHash, req.body.user, req.body.extent, req.body.amount, req.body.timestamp],
             (err) => {
                 if (err) {
                     next(err);
@@ -176,7 +193,10 @@ function initDatabase(): Promise<void>{
             "CREATE TABLE IF NOT EXISTS transfers( " +
             "id INTEGER PRIMARY KEY, " +
             "hash TEXT NOT NULL, " +
-            "user TEXT NOT NULL " +
+            "user TEXT NOT NULL, " +
+            "timestamp INTEGER NOT NULL, " +
+            "amount INTEGER NOT NULL, " +
+            "extent TEXT NOT NULL " +            
             ");",
             (err) => {
                 if (err) {