-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_oldFunc.js
executable file
·174 lines (156 loc) · 4.92 KB
/
backup_oldFunc.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
exports.readCommentsFromMongo = function (userId, contentId, slideNumber, callback) {
MongoClient.connect(url, function (err, db) {
if (err) throw err;
else {
console.log("Connected successfully to db");
findComments(userId, contentId, slideNumber, db, function (result, err) {
if (err) throw err;
db.close();
callback(result);
});
}
});
};
// Write to "contents" db
exports.writeCommentToMongo = function (data, userId, contentId, callback) {
MongoClient.connect(url, function (err, db) {
if (err) throw err;
else {
console.log("Connected successfully to server");
saveComment(db, userId, contentId, data, function (result, err) {
if (err) throw err;
db.close();
callback(result);
});
}
});
};
//phase out
exports.readAllCommentsFromMongo = function (userId, callback) {
MongoClient.connect(url, function (err, db) {
if (err) throw err;
else {
console.log("Connected successfully to db");
findAllComments(userId, db, function (result, err) {
if (err) throw err;
db.close();
callback(result);
});
}
});
};
// saves content to "contents" db
const saveComment = function (db, userId, contentId, data, callback) {
console.log(data);
var time = data.time;
var newComment = data.comment;
var parent = data.parent;
var slideNumber = data.slideNumber;
var accessUser = data.accessUser;
const collection = db.collection('comments');
collection.insertOne({
"contentId": contentId,
'userId': userId,
"accessUser": accessUser,
"time": time,
"comment": newComment,
"parent": parent,
"slideNumber": slideNumber
}, function (err, result) {
if (err) throw err;
console.log(result);
callback(result);
});
}
// Returns full JSON of specified user id and content id
const findAllComments = function (userId, db, callback) {
const collection = db.collection('comments');
collection.find({'userId': userId}).toArray(function (err, result) {
if (err) throw err;
console.log("db response: ")
console.log(result)
callback(result);
});
}
// Returns full JSON of specified user id and content id
const findComments = function (userId, contentId, slideNumber, db, callback) {
const collection = db.collection('comments');
collection.find({
'contentId': contentId,
'userId': userId,
'slideNumber': slideNumber
}).toArray(function (err, result) {
if (err) throw err;
console.log("db response: ")
console.log(result)
callback(result);
});
}
// JUST FOR ME TO REMEMBER --> nothing used in the build right now
function markusDo(collection, operation, ...params) {
//Genius
return new Promise(function (resolve, reject) {
const query = operation === 'find'
? () => collection[operation](...params).toArray()
: () => collection[operation](...params)
query()
.then(resolve)
.catch(err => {
reject(err)
throw err
})
})
}
const delayerWrap = function (queryFunc) {
return new Promise(function (resolve, reject) {
queryFunc()
.then(dat => {
console.log('HHAA', dat);
resolve(dat)
})
.catch(error => {
throw error;
reject(error)
})
})
}
// /***************************
// Deleting from Mongo (helpers)
// ****************************/
// const removeDocument = function(db, mongoId, callback) {
// const collection = db.collection('graph');
// collection.deleteOne({"_id": ObjectId(mongoId)}, function(err, result) {
// if (err) throw err;
// assert.equal(err, null);
// callback(result);
// });
// }
async function fetchRepoInfos () {
// load repository details for this array of repo URLs
const repos = [
{
url: 'https://api.github.com/repos/fs-opensource/futureflix-starter-kit'
},
{
url: 'https://api.github.com/repos/fs-opensource/android-tutorials-glide'
}
]
// map through the repo list
const promises = repos.map(async repo => {
// request details from GitHub’s API with Axios
const response = await Axios({
method: 'GET',
url: repo.url,
headers: {
Accept: 'application/vnd.github.v3+json'
}
})
return {
name: response.data.full_name,
description: response.data.description
}
})
// wait until all promises resolve
const results = await Promise.all(promises)
// use the results
}