-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotion.js
66 lines (59 loc) · 2.14 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const { Client } = require("@notionhq/client")
const notion = new Client({
auth: process.env.NOTION_TOKEN
})
const names = {
link: 'Link to the position/ Посилання на позицію / Ссылка на предложение',
email: 'Email/ Эл. адрес',
city: 'City/ Місто / Город',
country: 'Country / Країна / Страна',
site: 'Website/ Веб-сайт',
position: 'Position title/ Назва посади / Название должности',
company: 'Company/ Компанія / Компания'
}
const simplify = (row) => {
return {
id: row.id,
notionUrl: 'https://uaworks.org/' + row.id.replace(/[^\w\s]/gi, ''),
link: row.properties[names.link]?.url,
email: row.properties[names.email]?.email,
city: row.properties[names.city]?.rich_text[0]?.text?.content,
company: row.properties[names.company]?.rich_text[0]?.text?.content,
country: row.properties[names.country]?.multi_select.map((e) => e.name),
website: row.properties[names.site]?.url,
position: row.properties[names.position]?.title[0].text.content
}
}
module.exports.fetchNewJobs = async () => {
const newJobsPage = await notion.databases.query({
database_id: process.env.DATABASE_ID,
filter: {
and: [
{
property: "Reviewed",
checkbox: {
equals: true,
},
},
{
property: "tg_published",
checkbox: {
equals: false,
}
}
]
},
})
console.info(`Notion: ${newJobsPage.results.length} new jobs fetched`);
return newJobsPage.results.map(simplify)
}
module.exports.markAsPublished = async (jobs) => {
jobs.forEach(job => {
notion.pages.update({
page_id: job.id,
properties: {
tg_published: { checkbox: true}
}
})
})
}