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 = {
|
||||
// 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,
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue