From 10cca7f05d3442af1d9efc18d02c110f0f40e54a Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Thu, 4 Apr 2024 10:43:39 +0800 Subject: [PATCH] find the title property and update its name to Title --- .../api/src/resolvers/integrations/index.ts | 5 +++- .../api/src/services/integrations/notion.ts | 23 ++++++------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/packages/api/src/resolvers/integrations/index.ts b/packages/api/src/resolvers/integrations/index.ts index b1fc0c03a..502b06880 100644 --- a/packages/api/src/resolvers/integrations/index.ts +++ b/packages/api/src/resolvers/integrations/index.ts @@ -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 diff --git a/packages/api/src/services/integrations/notion.ts b/packages/api/src/services/integrations/notion.ts index 31ffc2cff..ef9b63319 100644 --- a/packages/api/src/services/integrations/notion.ts +++ b/packages/api/src/services/integrations/notion.ts @@ -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: {},