Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMarin15 committed Sep 23, 2023
1 parent 2f1a45b commit cc0b452
Show file tree
Hide file tree
Showing 3 changed files with 351 additions and 0 deletions.
89 changes: 89 additions & 0 deletions scripts/index.js
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)
246 changes: 246 additions & 0 deletions scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions scripts/package.json
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"
}
}

0 comments on commit cc0b452

Please sign in to comment.