-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotion.js
44 lines (37 loc) · 977 Bytes
/
notion.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
const { Client } = require('@notionhq/client');
const notion = new Client({ auth: process.env.NOTION_API_KEY });
exports.getTodoTasks = async function() {
const data = {
"Personal": [],
"Work": [],
"Others": []
};
const response = await notion.databases.query({
database_id: process.env.NOTION_DB_ID,
"filter": {
"property": "Done",
"checkbox": {
"equals": false
}
},
"sorts": [
{
"property": "Priority",
"direction": "ascending"
},
{
"timestamp": "created_time",
"direction": "ascending"
}
]
});
const results = response.results;
for(var i = 0; i < results.length; i++) {
const result = results[i];
const category = result.properties["Tags"].select?.name || "Others";
const task = result.properties["Name"].title[0].plain_text;
data[category].push(task);
}
console.log(data);
return data;
}