-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
57 lines (45 loc) · 1.52 KB
/
api.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 rp = require('request-promise')
const api_settings = require('./api_settings')
exports.getDocumentsByKeyword = (session, keyword) => {
doRequestAndSendResultDialog(session, 'keyword/like/' + keyword)
}
exports.getDocumentsByDoctype = (session, doctype) => {
doRequestAndSendResultDialog(session, 'doctype/like/' + doctype)
}
exports.getDocumentsByEntity = (session, entity) => {
doRequestAndSendResultDialog(session, 'name_entity/like/' + entity)
}
exports.getDocumentsByPlace = (session, place) => {
doRequestAndSendResultDialog(session, 'place/like/' + place)
}
doRequestAndSendResultDialog = (session, apiPath) => {
let apiPromise = rp({
uri: api_settings.baseUrl + '/database/api/v1.0/' + apiPath,
json: true
})
Promise.all([session, apiPromise])
.then((values) => {
let session = values[0]
let jsonData = values[1]
session.replaceDialog('InternalResultsDialog', jsonData)
})
.catch((err) => {
console.error(err)
})
}
exports.sendPdfDisplay = (id) => {
rp({
method: 'POST',
uri: api_settings.baseUrl + '/pdf/' + id,
})
.then((v) => 0)
.catch((err) => console.error(err))
}
exports.getAndSendSummary = (session, id) => {
rp({
uri: api_settings.baseUrl + '/database/api/v1.0/summary/' + id,
json: true
})
.then((jsonData) => session.replaceDialog('InternalSummaryDialog', jsonData.summary))
.catch((err) => console.error(err))
}