diff --git a/src/modules/sendToNotionDB.js b/src/modules/sendToNotionDB.js index 2bc9086..22ce656 100644 --- a/src/modules/sendToNotionDB.js +++ b/src/modules/sendToNotionDB.js @@ -1,25 +1,25 @@ const { Client } = require('@notionhq/client'); const config = require('../config'); -const notion = new Client({ auth: config.NOTION_INTEGRATION_TOKEN }); +// データベースIDのクリーニング:トリムと引用符の除去 +const cleanDatabaseId = config.NOTION_DATABASE_ID.trim().replace(/"/g, ''); -// 空白を削除 -const trimmedDatabaseId = config.NOTION_DATABASE_ID.trim(); +const notion = new Client({ auth: config.NOTION_INTEGRATION_TOKEN }); async function sendWeeklyDataToNotion(completedTasks, incompleteTasks, achievementRate, feedback) { console.log('Starting sendWeeklyDataToNotion function'); console.log('Config:', { NOTION_INTEGRATION_TOKEN: config.NOTION_INTEGRATION_TOKEN ? 'Set (not shown for security)' : 'Not set', - NOTION_DATABASE_ID: trimmedDatabaseId // CI/CD時の問題解決策 + NOTION_DATABASE_ID: cleanDatabaseId }); try { const today = new Date(); - // const period = `${today.getFullYear()}/${today.getMonth() + 1}/${today.getDate()}`; const period = "8/19-8/25"; - const response = await notion.pages.create({ - parent: { database_id: config.NOTION_DATABASE_ID }, + console.log('Preparing data for Notion API'); + const notionData = { + parent: { database_id: cleanDatabaseId }, properties: { '期間': { title: [{ text: { content: period } }] @@ -30,19 +30,23 @@ async function sendWeeklyDataToNotion(completedTasks, incompleteTasks, achieveme '未完了タスク': { rich_text: [{ text: { content: incompleteTasks } }] }, - // '達成率': { - // number: achievementRate - // }, '感想': { rich_text: [{ text: { content: feedback } }] }, }, - }); + }; + + console.log('Sending request to Notion API'); + console.log('Request data:', JSON.stringify(notionData, null, 2)); + + const response = await notion.pages.create(notionData); - console.log('データがNotionに追加されました:', response); + console.log('Data successfully added to Notion'); + console.log('Response:', JSON.stringify(response, null, 2)); return response; } catch (error) { - console.error('Notionへのデータ追加エラー:', error); + console.error('Error adding data to Notion:', error); + console.error('Error details:', JSON.stringify(error, Object.getOwnPropertyNames(error))); throw error; } }