mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
🐛 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:
parent
4df958807d
commit
345fa7c9c3
|
@ -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,
|
||||||
|
|
|
@ -126,11 +126,13 @@ 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) {
|
||||||
|
if (user.type === 'person') {
|
||||||
returnData.push({
|
returnData.push({
|
||||||
name: user.name,
|
name: user.name,
|
||||||
value: user.id,
|
value: user.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return returnData;
|
return returnData;
|
||||||
},
|
},
|
||||||
async getDatabaseIdFromPage(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getDatabaseIdFromPage(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
|
|
|
@ -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,11 +134,13 @@ 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) {
|
||||||
|
if (user.type === 'person') {
|
||||||
returnData.push({
|
returnData.push({
|
||||||
name: user.name,
|
name: user.name,
|
||||||
value: user.id,
|
value: user.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return returnData;
|
return returnData;
|
||||||
},
|
},
|
||||||
async getDatabaseIdFromPage(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getDatabaseIdFromPage(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue