-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.js
58 lines (53 loc) · 2.46 KB
/
auth.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
//process.env.NODE_TLS_REJECT_UNAUTHORIZED='0'
var express = require('express') , bodyParser = require('body-parser');
var request = require('request');
const cors = require('cors');
var app = express();
var data;
var baseurl = 'https://chequechain.wasplabs.ca/accounts?finInstNum=';
app.use(bodyParser.json());
app.use(cors())
app.post('/', function(req, res){
data = req.body;
data.processed = false;
//console.log(data); // your JSON
var now = new Date();
now.setHours(0,0,0,0);
var comp = new Date(data.date)
comp.setHours(0, 0, 0, 0);
//console.log(now)
//console.log(comp)
if( comp.getTime() <= now.getTime()){
data.processed = true;
data.accountvalid = false;
data.amountvalid = false;
}
if(data.processed == true){
var url = baseurl.concat(data.finInstNum, '&tranNum=', data.tranNum,'&bodyLimit=10&pageLimit=1');
request(url, function (error, response, body){
//console.log(error)
if ( response.statusCode == "200"){
data.statusCode = response.statusCode;
var jsonlist = JSON.parse(body);
for ( var i = 0; i < jsonlist.length ; i ++){
var tmp = jsonlist[i];
console.log(data.accountId);
if (data.accountId == tmp.accountId){
data.accountvalid = true;
//console.log(tmp);
data.balance = tmp.balance;
if (data.balance >= data.amount){
data.amountvalid = true;
}
}
}
}
//console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
//console.log(data);
res.send(data);
});
}else{
res.send(data);
}
});
app.listen(3000);