Browse Source

Merge branch 'master' into iroha-helpers-impl

kunickyd 3 năm trước cách đây
mục cha
commit
b5cc4aa042
4 tập tin đã thay đổi với 31 bổ sung12 xóa
  1. 4 1
      .gitignore
  2. 9 6
      app.ts
  3. 11 5
      package.json
  4. 7 0
      tsconfig.json

+ 4 - 1
.gitignore

@@ -128,4 +128,7 @@ dist
 
 package-lock.json
 .vscode
-.vs
+.vs
+
+#Build folder
+build

+ 9 - 6
app.js → app.ts

@@ -13,8 +13,8 @@ import iroha from 'iroha-helpers'
 const app = express();
 app.use(bodyParser.json());
 app.use(basicAuth({
-    users: { 'admin': 'superPasswd' },
-    challange: true
+users: { admin: 'superPasswd' },
+challenge: true
 }));
 
 const IROHA_ADMIN_PRIV = "f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70";
@@ -24,6 +24,7 @@ const commandService = new CommandService(IROHA_ADDRESS, grpc.credentials.create
 const queryService = new QueryService(IROHA_ADDRESS, grpc.credentials.createInsecure());
 
 
+
 const CHAIN4ALL_SERVICE_PORT = process.env.CHAIN4ALL_SERVICE_PORT || 3000;
 const IROHA_API_HOST = process.env.IROHA_API_HOST || "http://localhost";
 const IROHA_API_PORT = process.env.IROHA_API_PORT || 5000;
@@ -31,7 +32,7 @@ const IROHA_API_PORT = process.env.IROHA_API_PORT || 5000;
 const IROHA_DOMAIN = process.env.IROHA_DOMAIN || "test";
 const IROHA_ASSET = process.env.IROHA_ASSET || "coin";
 const DATA_OWNER = process.env.DATA_OWNER || "admin"
-const PRICE_MODIFIER = process.env.PRICE_MODIFIER || 0.5;
+const PRICE_MODIFIER: number = parseFloat(process.env.PRICE_MODIFIER || "0.5");
 
 app.get("/", (req, res) => {
     res.send("Chain4All Blockchain service");
@@ -75,6 +76,7 @@ app.post("/buy", async (req, res, next) => {
     }
 });
 
+
 function isTransacationValid(){
     
 }
@@ -103,7 +105,8 @@ async function getTransactionDetail(txHash, user) {
     return quer.transactionsList[0].payload.reducedPayload.commandsList[0].transferAsset; 
 }
 
-function getArea(extent) {
+function getArea(extent: Array<Array<number>>) : number {
+
     let y1 = extent[0][1];
     let y4 = extent[3][1];
 
@@ -116,11 +119,11 @@ function getArea(extent) {
     return height * width;
 }
 
-function getPrice(extent) {
+function getPrice(extent: Array<Array<number>>) : number{
     return getArea(extent) * PRICE_MODIFIER;
 }
 
-function errorMiddleware(err, req, res, next) { //TODO: add custom Exception class
+function errorMiddleware(err: any, req: any, res: any, next: any): void { //TODO: add custom Exception class
     console.log(err);
     res.status(500);
     res.send(err.message);

+ 11 - 5
package.json

@@ -2,11 +2,11 @@
   "name": "chain4all",
   "version": "1.0.0",
   "description": "",
-  "main": "app.js",
-  "type": "module",
+  "main": "build/app.js",
   "scripts": {
-    "dev": "nodemon app.js",
-    "start": "node app.js"
+    "dev": "nodemon app.ts",
+    "start": "node build/app.js",
+    "build": "tsc --project ./"
   },
   "author": "Daniel Kunický",
   "license": "ISC",
@@ -19,7 +19,13 @@
     "iroha-helpers": "^1.3.0"
   },
   "devDependencies": {
-    "nodemon": "^2.0.15"
+    "@tsconfig/node10": "^1.0.8",
+    "@types/body-parser": "^1.19.2",
+    "@types/express": "^4.17.13",
+    "@types/node": "^17.0.16",
+    "nodemon": "^2.0.15",
+    "ts-node": "^10.5.0",
+    "typescript": "^4.5.5"
   },
   "nodemonConfig": {
     "ext": "js",

+ 7 - 0
tsconfig.json

@@ -0,0 +1,7 @@
+{
+    "extends": "@tsconfig/node10/tsconfig.json",    
+    "compilerOptions": {        
+        "rootDir": "./",
+        "outDir": "./build",       
+    }
+}