🐛 Fix bug and add improvements to Notion (#2750)

* 🐛 Fix bug when filtering columns type number

* 🐛 Fix issue with date filtering

*  Enable file support in v2

*  Remvoe spaces when using comma-seperated relation ids

* 🐛 Fix issue that removes url and id when downloading data

*  Filter out bots when loading users
This commit is contained in:
Ricardo Espinoza 2022-02-24 17:27:06 -05:00 committed by GitHub
parent 4df958807d
commit 345fa7c9c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 18 deletions

View file

@ -266,7 +266,7 @@ function getPropertyKeyValue(value: any, type: string, timezone: string, version
result = { result = {
// tslint:disable-next-line: no-any // tslint:disable-next-line: no-any
type: 'relation', relation: (value.relationValue).reduce((acc: [], cur: 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; break;
@ -397,9 +397,7 @@ export function mapFilters(filters: IDataObject[], timezone: string) {
} else if (key === 'phone_number') { } else if (key === 'phone_number') {
key = 'phone'; key = 'phone';
} else if (key === 'date' && !['is_empty', 'is_not_empty'].includes(value.condition as string)) { } 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(); valuePropertyName = (value.date === '') ? {} : moment.tz(value.date, timezone).utc().format();
} else if (key === 'number') {
key = 'text';
} else if (key === 'boolean') { } else if (key === 'boolean') {
key = 'checkbox'; key = 'checkbox';
} }
@ -495,7 +493,7 @@ export function simplifyObjects(objects: any, download = false, version = 2) {
objects = [objects]; objects = [objects];
} }
const results: IDataObject[] = []; 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')) { if (object === 'page' && (parent.type === 'page_id' || parent.type === 'workspace')) {
results.push({ results.push({
id, 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') { } else if (download && json.object === 'page' && json.parent.type === 'database_id') {
results.push({ results.push({
json: { json: {
id, id: json.id,
...(version === 2) ? { name: getPropertyTitle(json.properties) } : {}, ...(version === 2) ? { name: getPropertyTitle(json.properties) } : {},
...(version === 2) ? { url } : {}, ...(version === 2) ? { url: json.url } : {},
...(version === 2) ? { ...prepend('property', simplifyProperties(json.properties)) } : { ...simplifyProperties(json.properties) }, ...(version === 2) ? { ...prepend('property', simplifyProperties(json.properties)) } : { ...simplifyProperties(json.properties) },
}, },
binary, binary,

View file

@ -126,10 +126,12 @@ export class NotionV1 implements INodeType {
const returnData: INodePropertyOptions[] = []; const returnData: INodePropertyOptions[] = [];
const users = await notionApiRequestAllItems.call(this, 'results', 'GET', '/users'); const users = await notionApiRequestAllItems.call(this, 'results', 'GET', '/users');
for (const user of users) { for (const user of users) {
returnData.push({ if (user.type === 'person') {
name: user.name, returnData.push({
value: user.id, name: user.name,
}); value: user.id,
});
}
} }
return returnData; return returnData;
}, },

View file

@ -79,7 +79,7 @@ export class NotionV2 implements INodeType {
const { properties } = await notionApiRequest.call(this, 'GET', `/databases/${databaseId}`); const { properties } = await notionApiRequest.call(this, 'GET', `/databases/${databaseId}`);
for (const key of Object.keys(properties)) { for (const key of Object.keys(properties)) {
//remove parameters that cannot be set from the API. //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({ returnData.push({
name: `${key}`, name: `${key}`,
value: `${key}|${properties[key].type}`, value: `${key}|${properties[key].type}`,
@ -134,10 +134,12 @@ export class NotionV2 implements INodeType {
const returnData: INodePropertyOptions[] = []; const returnData: INodePropertyOptions[] = [];
const users = await notionApiRequestAllItems.call(this, 'results', 'GET', '/users'); const users = await notionApiRequestAllItems.call(this, 'results', 'GET', '/users');
for (const user of users) { for (const user of users) {
returnData.push({ if (user.type === 'person') {
name: user.name, returnData.push({
value: user.id, name: user.name,
}); value: user.id,
});
}
} }
return returnData; return returnData;
}, },
@ -148,7 +150,7 @@ export class NotionV2 implements INodeType {
const { properties } = await notionApiRequest.call(this, 'GET', `/databases/${databaseId}`); const { properties } = await notionApiRequest.call(this, 'GET', `/databases/${databaseId}`);
for (const key of Object.keys(properties)) { for (const key of Object.keys(properties)) {
//remove parameters that cannot be set from the API. //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({ returnData.push({
name: `${key}`, name: `${key}`,
value: `${key}|${properties[key].type}`, value: `${key}|${properties[key].type}`,
@ -285,7 +287,6 @@ export class NotionV2 implements INodeType {
responseData = await notionApiRequest.call(this, 'POST', `/search`, body); responseData = await notionApiRequest.call(this, 'POST', `/search`, body);
responseData = responseData.results; responseData = responseData.results;
} }
if (simple === true) { if (simple === true) {
responseData = simplifyObjects(responseData, download); responseData = simplifyObjects(responseData, download);
} }