find the title property and update its name to Title

This commit is contained in:
Hongbo Wu
2024-04-04 10:43:39 +08:00
parent 40fccf52cd
commit 10cca7f05d
2 changed files with 11 additions and 17 deletions

View File

@ -96,7 +96,10 @@ export const setIntegrationResolver = authorized<
if (integration.name.toLowerCase() === 'readwise') {
// create a task to export all the items for readwise temporarily
await enqueueExportToIntegration(integration.id, uid)
} else if (integration.name.toLowerCase() === 'notion') {
} else if (
integration.name.toLowerCase() === 'notion' &&
integration.settings
) {
const settings = integration.settings as { parentDatabaseId?: string }
if (settings.parentDatabaseId) {
// update notion database properties

View File

@ -369,26 +369,17 @@ export class NotionClient implements IntegrationClient {
updateDatabase = async (databaseId: string) => {
const database = await this.findDatabase(databaseId)
// find the title property and update it
const titleProperty = Object.entries(database.properties).find(
([, property]) => property.type === 'title'
)
const title = titleProperty ? titleProperty[0] : 'Name'
await this.client.databases.update({
database_id: database.id,
title: [
{
text: {
content: 'Library',
},
},
],
description: [
{
text: {
content: 'Library of saved items from Omnivore',
},
},
],
properties: {
Title: {
title: {},
[title]: {
name: 'Title',
},
Author: {
rich_text: {},