-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f1a45b
commit cc0b452
Showing
3 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const { Client } = require("@notionhq/client"); | ||
require("dotenv").config({ | ||
path: ".env.local", | ||
}); | ||
|
||
// Initializing a client | ||
const notion = new Client({ | ||
auth: process.env.NOTION_INTEGRATION_SECRET, | ||
}); | ||
|
||
async function deleteRecords(databaseId) { | ||
const response = await queryDb(databaseId); | ||
|
||
console.log(response); | ||
|
||
response.results.forEach(async (item) => { | ||
await notion.pages.update({ | ||
page_id: item.id, | ||
archived: true, | ||
}); | ||
}); | ||
} | ||
|
||
async function updateDb(sourceDbId, destDbId) { | ||
const source = await queryDb(sourceDbId); | ||
|
||
for (const item of source.results) { | ||
const properties = { | ||
Name: { | ||
title: [ | ||
{ | ||
text: { | ||
content: item.properties.Name.title[0].text.content, | ||
}, | ||
}, | ||
], | ||
}, | ||
|
||
Position: { | ||
select: { | ||
name: item.properties.Position.select.name, | ||
}, | ||
}, | ||
|
||
Avatar: { | ||
files: [{ | ||
name: item.properties.Avatar.files[0]?.name ?? "test.jpg", | ||
type: item.properties.Avatar.files[0]?.type, | ||
file: { | ||
url: item.properties.Avatar.files[0]?.file.url, | ||
|
||
} | ||
}] | ||
} | ||
} | ||
|
||
if(item.properties.Avatar.files.length === 0) { | ||
|
||
delete properties.Avatar | ||
|
||
|
||
} | ||
|
||
await notion.pages.create({ | ||
parent: { | ||
type: "database_id", | ||
database_id: destDbId, | ||
}, | ||
|
||
properties | ||
|
||
}); | ||
} | ||
} | ||
|
||
async function queryDb(databaseId) { | ||
const response = await notion.databases.query({ | ||
database_id: databaseId, | ||
}); | ||
|
||
console.log(response.results[response.results.length-1].properties.Avatar.files[0].name) | ||
return response; | ||
} | ||
|
||
deleteRecords(process.env.NOTION_LEADS_PRODDB); | ||
|
||
// queryDb(`bbbd878ff5f6489c8c39e6f54166d31e`) | ||
|
||
updateDb(process.env.NOTION_LEADS_DEVDB, process.env.NOTION_LEADS_PRODDB) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "scripts", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "node index.js" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@notionhq/client": "^2.2.13", | ||
"dotenv": "^16.3.1" | ||
} | ||
} |