Skip to content

Commit

Permalink
🚑 deployFix: database idから引用符も削除
Browse files Browse the repository at this point in the history
  • Loading branch information
Suke-H committed Sep 7, 2024
1 parent b50b691 commit 93229e7
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/modules/sendToNotionDB.js
Original file line number Diff line number Diff line change
@@ -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 } }]
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 93229e7

Please sign in to comment.