-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
52 lines (45 loc) · 1.11 KB
/
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
// Gets all comments for specific post
const getAllComments = async (postsModel) => {
let comments = [];
for (let i = 0; i < postsModel.length; i++) {
comments.push(await postsModel[i].getComments());
}
return comments;
};
const getLikes = async (likeModel, postsModel) => {
let likes = [];
for (let i = 0; i < postsModel.length; i++) {
likes.push(
await likeModel.findAndCountAll({
where: {
PostId: postsModel[i].id
}
})
);
}
return likes;
};
// change the userId argument to be dynamic
const followingIds = async (userModel, userId = 2) => {
let user = await userModel.findAll({
where: {
id: userId
},
include: 'following'
});
console.log('following', user[0].dataValues.following);
let followingIdsForPosts = user[0].dataValues.following.map(
(users) => users.dataValues.id
);
console.log('IDS FOR POSTS', followingIdsForPosts);
return followingIdsForPosts;
};
const prettyLogs = (object) => {
console.log(JSON.stringify(object, null, 4));
};
module.exports = {
getAllComments,
getLikes,
followingIds,
prettyLogs
};