-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcourses.ts
More file actions
34 lines (31 loc) · 922 Bytes
/
courses.ts
File metadata and controls
34 lines (31 loc) · 922 Bytes
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
import { Client } from '@notionhq/client'
export default defineEventHandler(async () => {
const notion = new Client({ auth: process.env.NOTION_API_KEY })
const databaseId = '52fcfd11b497413387ec15c9db5f4bd6'
const databaseContent = await notion.databases.query({
database_id: databaseId,
filter: {
and: [
{
property: 'Type',
multi_select: {
contains: 'Course',
},
},
],
},
})
const finalResults = databaseContent.results.map((item) => {
// Final form of data that's needed by the UI
return {
id: item.id,
publishUrl: item.properties['Publishing URL'].url,
title: item.properties.Name.title[0].text.content,
description:
item.properties.Description.rich_text.length > 0
? item.properties.Description.rich_text[0].text.content
: '',
}
})
return finalResults
})