From 345fa7c9c312679966a6599bd0f7a54e2a30df43 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Thu, 24 Feb 2022 17:27:06 -0500 Subject: [PATCH] :bug: Fix bug and add improvements to Notion (#2750) * :bug: Fix bug when filtering columns type number * :bug: Fix issue with date filtering * :zap: Enable file support in v2 * :zap: Remvoe spaces when using comma-seperated relation ids * :bug: Fix issue that removes url and id when downloading data * :zap: Filter out bots when loading users --- .../nodes-base/nodes/Notion/GenericFunctions.ts | 12 +++++------- .../nodes-base/nodes/Notion/v1/NotionV1.node.ts | 10 ++++++---- .../nodes-base/nodes/Notion/v2/NotionV2.node.ts | 15 ++++++++------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/nodes-base/nodes/Notion/GenericFunctions.ts b/packages/nodes-base/nodes/Notion/GenericFunctions.ts index 25dc59bc2b..14bd0e2080 100644 --- a/packages/nodes-base/nodes/Notion/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Notion/GenericFunctions.ts @@ -266,7 +266,7 @@ function getPropertyKeyValue(value: any, type: string, timezone: string, version result = { // tslint:disable-next-line: no-any type: 'relation', relation: (value.relationValue).reduce((acc: [], cur: any) => { - return acc.concat(cur.split(',').map((relation: string) => ({ id: relation }))); + return acc.concat(cur.split(',').map((relation: string) => ({ id: relation.trim() }))); }, []), }; break; @@ -397,9 +397,7 @@ export function mapFilters(filters: IDataObject[], timezone: string) { } else if (key === 'phone_number') { key = 'phone'; } else if (key === 'date' && !['is_empty', 'is_not_empty'].includes(value.condition as string)) { - valuePropertyName = (valuePropertyName !== undefined && !Object.keys(valuePropertyName).length) ? {} : moment.tz(value.date, timezone).utc().format(); - } else if (key === 'number') { - key = 'text'; + valuePropertyName = (value.date === '') ? {} : moment.tz(value.date, timezone).utc().format(); } else if (key === 'boolean') { key = 'checkbox'; } @@ -495,7 +493,7 @@ export function simplifyObjects(objects: any, download = false, version = 2) { objects = [objects]; } const results: IDataObject[] = []; - for (const { object, id, properties, parent, title, json, binary, url, created_time, last_edited_time } of objects) { + for (const { object, id, properties, parent, title, json, binary, url } of objects) { if (object === 'page' && (parent.type === 'page_id' || parent.type === 'workspace')) { results.push({ id, @@ -512,9 +510,9 @@ export function simplifyObjects(objects: any, download = false, version = 2) { } else if (download && json.object === 'page' && json.parent.type === 'database_id') { results.push({ json: { - id, + id: json.id, ...(version === 2) ? { name: getPropertyTitle(json.properties) } : {}, - ...(version === 2) ? { url } : {}, + ...(version === 2) ? { url: json.url } : {}, ...(version === 2) ? { ...prepend('property', simplifyProperties(json.properties)) } : { ...simplifyProperties(json.properties) }, }, binary, diff --git a/packages/nodes-base/nodes/Notion/v1/NotionV1.node.ts b/packages/nodes-base/nodes/Notion/v1/NotionV1.node.ts index 89d78682c3..a5356e8a1b 100644 --- a/packages/nodes-base/nodes/Notion/v1/NotionV1.node.ts +++ b/packages/nodes-base/nodes/Notion/v1/NotionV1.node.ts @@ -126,10 +126,12 @@ export class NotionV1 implements INodeType { const returnData: INodePropertyOptions[] = []; const users = await notionApiRequestAllItems.call(this, 'results', 'GET', '/users'); for (const user of users) { - returnData.push({ - name: user.name, - value: user.id, - }); + if (user.type === 'person') { + returnData.push({ + name: user.name, + value: user.id, + }); + } } return returnData; }, diff --git a/packages/nodes-base/nodes/Notion/v2/NotionV2.node.ts b/packages/nodes-base/nodes/Notion/v2/NotionV2.node.ts index 5c6ff65124..3f9b0432c8 100644 --- a/packages/nodes-base/nodes/Notion/v2/NotionV2.node.ts +++ b/packages/nodes-base/nodes/Notion/v2/NotionV2.node.ts @@ -79,7 +79,7 @@ export class NotionV2 implements INodeType { const { properties } = await notionApiRequest.call(this, 'GET', `/databases/${databaseId}`); for (const key of Object.keys(properties)) { //remove parameters that cannot be set from the API. - if (!['created_time', 'last_edited_time', 'created_by', 'last_edited_by', 'formula', 'files', 'rollup'].includes(properties[key].type)) { + if (!['created_time', 'last_edited_time', 'created_by', 'last_edited_by', 'formula', 'rollup'].includes(properties[key].type)) { returnData.push({ name: `${key}`, value: `${key}|${properties[key].type}`, @@ -134,10 +134,12 @@ export class NotionV2 implements INodeType { const returnData: INodePropertyOptions[] = []; const users = await notionApiRequestAllItems.call(this, 'results', 'GET', '/users'); for (const user of users) { - returnData.push({ - name: user.name, - value: user.id, - }); + if (user.type === 'person') { + returnData.push({ + name: user.name, + value: user.id, + }); + } } return returnData; }, @@ -148,7 +150,7 @@ export class NotionV2 implements INodeType { const { properties } = await notionApiRequest.call(this, 'GET', `/databases/${databaseId}`); for (const key of Object.keys(properties)) { //remove parameters that cannot be set from the API. - if (!['created_time', 'last_edited_time', 'created_by', 'last_edited_by', 'formula', 'files', 'rollup'].includes(properties[key].type)) { + if (!['created_time', 'last_edited_time', 'created_by', 'last_edited_by', 'formula', 'rollup'].includes(properties[key].type)) { returnData.push({ name: `${key}`, value: `${key}|${properties[key].type}`, @@ -285,7 +287,6 @@ export class NotionV2 implements INodeType { responseData = await notionApiRequest.call(this, 'POST', `/search`, body); responseData = responseData.results; } - if (simple === true) { responseData = simplifyObjects(responseData, download); }