This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
90 lines (74 loc) · 3.07 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* Aabo Technologies 2021
*/
'use-strict'
const express = require('express')
const asyncHandler = require('express-async-handler')
const enroll = require('./controllers/enroll')
const user = require('./controllers/user')
const invoke = require('./controllers/invoke')
const query = require('./controllers/query')
const app = express()
const port = 80
app.use(express.json())
const addCORSHeaders = (res, origin) => {
res.header('Access-Control-Allow-Origin', origin);
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, Cache-Control, Pragma');
return res
}
app.post('/enrollAdmin', asyncHandler(async (req, res, next) => {
const result = await enroll.main()
const origin = req.get('origin')
res = addCORSHeaders(res, origin)
res.send(result)
}))
app.post('/enrollUser', asyncHandler(async (req, res, next) => {
const result = await user.main()
const origin = req.get('origin')
res = addCORSHeaders(res, origin)
res.send(result)
}))
app.post('/test/enrollUser', asyncHandler(async (req, res, next) => {
const result = await invoke.testInvoke('user1')
const origin = req.get('origin')
res = addCORSHeaders(res, origin)
res.send(result)
}))
app.post('/passport/create/:id/:firstname/:lastname/:dob/:s3URL/:patientNumber/:country/:dynamoHash', asyncHandler( async (req, res, next) => {
const received = req.params
const origin = req.get('origin')
res = addCORSHeaders(res, origin)
const result = await invoke.createPassport(received.id,received.firstname,received.lastname,received.dob,received.s3URL,received.patientNumber,received.country,received.dynamoHash)
res.sendStatus(200)
}))
app.post('/passport/status/validation/:id/:status', asyncHandler(async (req, res, next) => {
const received = req.params
const origin = req.get('origin')
res = addCORSHeaders(res, origin)
const result = await invoke.changeValidationStatus(received.id,received.status)
res.sendStatus(200)
}))
app.post('/passport/status/vaccination/:id/:status', asyncHandler(async (req, res, next) => {
const received = req.params
const origin = req.get('origin')
res = addCORSHeaders(res, origin)
const result = await invoke.changeVaxStatus(received.id,received.status)
res.sendStatus(200)
}))
app.get('/passport/read/:id/:user', asyncHandler(async (req, res, next) => {
const received = req.params
const origin = req.get('origin')
res = addCORSHeaders(res, origin)
const result = await query.readPassport(received.id, received.user)
res.sendStatus(200)
}))
app.get('/passport/history/:id/:user', asyncHandler(async (req, res, next) => {
const received = req.params
const origin = req.get('origin')
res = addCORSHeaders(res, origin)
const result = await query.getHistoryForPassport(received.id, received.user)
res.sendStatus(200)
}))
app.listen(port, () => console.info('Blockchain API listening on port:', port))