-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudit.js
95 lines (87 loc) · 2.43 KB
/
audit.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
83
84
85
86
87
88
89
90
91
92
93
94
95
var AWS = require("aws-sdk");
let util = require("./utils");
let date_fns = require("./date_util");
let endpoint = util.get_endpoint();
const userInfo = require("./user_lookup");
AWS.config.update({
region: process.env.AWS_REGION,
endpoint: endpoint,
});
var docClient = new AWS.DynamoDB.DocumentClient();
async function insert_audit(
user_id,
followers,
unfollowers,
audit_comment,
first_time
) {
return new Promise(async function (resolve, reject) {
let audit = [];
let current_date = date_fns.getTodaysDate();
let n = await set_names(followers, unfollowers);
// store followers
let obj = { followers: n.followers };
audit.push(obj);
// store unfollowers
let obj1 = { unfollowers: n.unfollowers };
audit.push(obj1);
let id = `${user_id}-audit`;
let params = {
TableName: "twitter_followers",
Item: {
id: id,
date: current_date,
type: "audit",
audit: audit,
comment: audit_comment,
first_time: first_time,
},
};
console.log("insertAlarm : adding audit into twitter_follower ");
docClient.put(params, function (err, data) {
if (err) {
console.error(
"Unable to add audit Error JSON:",
JSON.stringify(err, null, 2)
);
reject(err);
} else {
console.log("Added audit : twitter_Followers");
resolve(data);
}
});
});
}
async function set_names(followers, unfollowers) {
let followers_names = [];
let unfollowers_name = [];
for (let f of followers) {
console.log(" f " + f);
if (typeof f !== "string") {
console.log("skipping followers user fetch for " + JSON.stringify(f));
continue;
}
let name = await userInfo.userInfo(f);
followers_names.push(name);
}
for (let u of unfollowers) {
console.log(" u " + u);
if (typeof u !== "string") {
console.log("skipping followers user fetch" + JSON.stringify(u));
continue;
}
let name = await userInfo.userInfo(u);
unfollowers_name.push(name);
}
return { followers: followers_names, unfollowers: unfollowers_name };
}
async function test_audit() {
let user_id = "tanmay_patil";
let followers = ["1234", "6666666666666666", "77777777777777777777"];
let unfollowers = ["888888888888888888888", "99999999999999999999"];
await insert_audit(user_id, followers, unfollowers);
}
//test_audit();
module.exports = {
insert_audit: insert_audit,
};