Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit af35862

Browse files
authored
Create Notification.js
1 parent 9a2b995 commit af35862

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

src/classes/Notification.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
let headers = require('../utils/headers.js');
2+
let variables = require('../utils/variables.js');
3+
4+
class Notifications {
5+
async answerNotification(after, count) {
6+
if (!global.cookies) {
7+
throw new Error('Not logged in.');
8+
} else {
9+
headers.Cookie = global.cookies;
10+
let info = await variables
11+
.fetch('https://repl.it/graphql', {
12+
method: 'POST',
13+
headers,
14+
body: JSON.stringify({
15+
query: `
16+
query AnswerAcceptedNotification($after: String!, $count: Int!) {
17+
notifications(after: $after, count: $count) {
18+
items {
19+
... on AnswerAcceptedNotification {
20+
id
21+
url
22+
text
23+
seen
24+
context
25+
creator {
26+
${variable.userAttributes}
27+
}
28+
timeCreated
29+
timeUpdated
30+
}
31+
}
32+
pageInfo {
33+
nextCursor
34+
}
35+
}
36+
}`,
37+
variables: {
38+
after,
39+
count
40+
}
41+
})
42+
})
43+
.then(res => res.json());
44+
45+
if (!info.data.notifications) {
46+
throw new Error(`Cannot fetch notifications.`);
47+
} else {
48+
return info.data.notifications;
49+
}
50+
}
51+
}
52+
}
53+
54+
module.exports = {
55+
Notifications: Notifications
56+
};

0 commit comments

Comments
 (0)