-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (50 loc) · 1.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const fabricClient = require('./fabricClient.js');
const utils = require('./utils.js');
const app = express();
app.use(morgan('tiny'));
app.use(cors());
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.json({
message: 'Behold The CFEVN Stack!'
});
});
app.get('/queryResponse', (req, res) => {
fabricClient.queryBatchList().then(response => utils.processBatchList(response)).then((response) => {
res.json(response);
});
});
app.post('/queryBatch', (req, res) => {
fabricClient.queryBatch(req.body.id).then((response) => {
res.json(response)
}).catch((error) => {
res.status(500);
res.json(error);
});
});
app.post('/createBatch', (req, res) => {
let str = JSON.stringify(req.body);
fabricClient.createBatch(str).then((response) => {
res.json(response);
}).catch((error) => {
res.status(500);
res.json(error);
});
});
app.post('/updateBatch', (req, res) => {
let data = JSON.stringify(req.body.data);
fabricClient.updateBatch(req.body.id, req.body.stage, data).then((response) => {
res.json(response);
}).catch((error) => {
res.status(500);
res.json(error);
});
})
const port = process.env.PORT || 4000;
app.listen(port, () => {
console.log(`listening on ${port}`);
});