|
|
@@ -6,10 +6,12 @@ import basicAuth from "express-basic-auth"
|
|
|
const app = express();
|
|
|
app.use(bodyParser.json());
|
|
|
app.use(basicAuth({
|
|
|
- users : { 'admin' : 'superPasswd' },
|
|
|
- challange : true
|
|
|
+ users: { admin: 'superPasswd' },
|
|
|
+ challenge: true
|
|
|
}));
|
|
|
|
|
|
+
|
|
|
+
|
|
|
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;
|
|
|
@@ -17,7 +19,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");
|
|
|
@@ -44,14 +46,14 @@ app.post("/buy", async (req, res, next) => {
|
|
|
if (!req.body.txHash) {
|
|
|
res.status(400);
|
|
|
throw Error(JSON.stringify({ error: { name: "Error, request body has no \"txHash\" property!" } }));
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
catch (err) {
|
|
|
next(err);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-function getArea(extent) {
|
|
|
+function getArea(extent: Array<Array<number>>) : number {
|
|
|
let y1 = extent[0][1];
|
|
|
let y4 = extent[3][1];
|
|
|
|
|
|
@@ -64,11 +66,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);
|