-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
60 lines (50 loc) · 1.66 KB
/
app.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
const express = require('express')
const trawler = require('@gftc/trawler')
const app = express()
const port = process.env.PORT || 3000;
const bodyParser = require('body-parser')
const multer = require('multer') // v1.0.5
const upload = multer() // for parsing multipart/form-data
app.use(bodyParser.json()) // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
app.post('/profile', upload.array(), function (req, res, next) {
console.log(req.body)
res.json(req.body)
})
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.post('/csv', upload.array(), async function (req, res, next) {
console.log(req.body);
const [
bdhXml,
epcClassXml,
locationXml,
objectEventXmlList,
transformationEventXmlList,
aggregationEventXmlList
] = await Promise.all([
trawler.createBusinessDocumentHeaderXml(req.body.businessHeaderCsv),
trawler.createEpcClassXml(req.body.epcClassCsv),
trawler.createLocationHeaderXml(req.body.locationCsv),
trawler.createObjectEventXml(req.body.objectEventCsv),
trawler.createTransformationEventXml(req.body.transformationEventCsv),
trawler.createAggregationEventXml(req.body.aggregationEventCsv)
])
// Combine the generator's result to create the final EPCIS document
const result = trawler.createTrawlerXml({
bdhXml,
epcClassXml,
locationXml,
xmlList: [
...objectEventXmlList,
...transformationEventXmlList,
...aggregationEventXmlList
]
})
console.log(result);
res.send(result);
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})