-
Notifications
You must be signed in to change notification settings - Fork 2
/
interpret.js
81 lines (77 loc) · 1.98 KB
/
interpret.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
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
const logResults = async () => {
const results = [];
const posts = await prisma.whosHiring.findMany({});
await Promise.all(
posts.map(
(post) =>
new Promise(async (resolve) => {
const oneDayLater = new Date(
Number(post.createdAt) + 1000 * 60 * 60 * 24
);
const oneDayCommentsCount = await prisma.comment.count({
where: {
parent: post,
createdAt: {
lt: oneDayLater,
},
NOT: [
{
content: {
equals: null,
},
},
{
content: {
equals: "",
},
},
],
},
});
const threeDaysLater = new Date(
Number(post.createdAt) + 1000 * 60 * 60 * 24 * 3
);
const threeDayCommentsCount = await prisma.comment.count({
where: {
parent: post,
createdAt: {
lt: threeDaysLater,
},
NOT: [
{
content: {
equals: null,
},
},
{
content: {
equals: "",
},
},
],
},
});
if (threeDayCommentsCount) {
results.push({
createdAt: post.createdAt,
oneDayCommentsCount,
threeDayCommentsCount,
});
}
resolve();
})
)
);
results
.sort((a, b) => a.createdAt - b.createdAt)
.forEach((post) => {
console.log(
`"${post.createdAt.toLocaleString()}", ${post.oneDayCommentsCount}, ${
post.threeDayCommentsCount
}`
);
});
};
logResults();