-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhandler.js
82 lines (69 loc) · 2.37 KB
/
handler.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
'use strict';
var utils = require('./lib/utils.js');
var querystring = require('querystring');
var http = require('http');
// Add Donations
module.exports.new = (event, context, callback) => {
var data = JSON.parse('{"' + decodeURI(event.body).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}')
data.type= 'Donations';
data.address= data.addresss;
data.city= data.town;
data.created_at= new Date().getTime() ;
data.udpated_at= new Date().getTime() ;
var data_query = querystring.stringify(data);
var options = {
host: 'reliefsupports.org',
path: '/api/v1/entry/donations',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(data_query)
}
};
console.log("query: " + data_query);
var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log("body: " + chunk);
console.log("data: " + data);
utils.add(event,'data',data,callback);
});
});
req.write(data_query);
req.end();
};
// Add Needs
module.exports.newneeds = (event, context, callback) => {
var data = JSON.parse('{"' + decodeURI(event.body).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}')
data.type = 'Needs';
data.address= data.addresss;
data.addresss = undefined;
data.city= data.town;
data.created_at= new Date().getTime() ;
data.udpated_at= new Date().getTime() ;
var data_query = querystring.stringify(data);
var options = {
host: 'reliefsupports.org',
path: '/api/v1/entry/needs',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(data_query)
}
};
console.log("query: " + data_query);
var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log("body: " + chunk);
console.log("data: " + data);
utils.add(event,'data',data,callback);
});
});
req.write(data_query);
req.end();
};
// View All
module.exports.view = (event, context, callback) => {
utils.find(event,'data',{},{_id: -1},callback);
};