-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
52 lines (46 loc) · 999 Bytes
/
utils.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
const fs = require("fs");
const request = require("request");
const CONFIG_PATH = "./config.json";
function notifySlack(url, body) {
var options = {
method: 'POST',
url: url,
headers: {
'Content-Type': 'application/json'
},
body: body,
json: true
};
request(options, function (error, response, body) {
if (error)
console.log("Err: ", err);
});
}
function resp(res, statusCode, msg, data = null) {
try {
return res.status(statusCode).json({
'error': (statusCode === 200) ? false : true,
'message': msg,
'data': data
});
} catch (err) {
console.log(err);
}
}
function makeJSON(statusCode, msg, data = null) {
return {
'code': statusCode,
'message': msg,
'data': data
};
}
function parseConfig() {
let json = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
return json;
}
module.exports = {
'res': resp,
'makeJSON': makeJSON,
'parseConfig': parseConfig,
'notifySlack': notifySlack
}