Wordpress node

This commit is contained in:
Ricardo Espinoza 2020-01-02 17:34:48 -05:00
parent c490d4bc84
commit f16b8a57a0
4 changed files with 862 additions and 372 deletions

View file

@ -40,24 +40,24 @@ export async function wordpressApiRequest(this: IExecuteFunctions | IExecuteSing
} }
} }
export async function intercomApiRequestAllItems(this: IExecuteFunctions, propertyName: string, method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any export async function wordpressApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const returnData: IDataObject[] = []; const returnData: IDataObject[] = [];
let responseData; let responseData;
query.per_page = 10; query.per_page = 10;
query.page = 1; query.page = 0;
let uri: string | undefined; let uri: string | undefined;
do { do {
responseData = await wordpressApiRequest.call(this, method, endpoint, body, query, uri); query.page++;
uri = responseData.pages.next; responseData = await wordpressApiRequest.call(this, method, endpoint, body, query, uri, { resolveWithFullResponse: true });
returnData.push.apply(returnData, responseData.body);
} while ( } while (
responseData.pages !== undefined && responseData.headers['x-wp-totalpages'] !== undefined &&
responseData.pages.next !== undefined && parseInt(responseData.headers['x-wp-totalpages'], 10) < query.page
responseData.pages.next !== null
); );
return returnData; return returnData;

View file

@ -16,7 +16,27 @@ export const postOperations = [
{ {
name: 'Create', name: 'Create',
value: 'create', value: 'create',
description: ``, description: 'Create a post',
},
{
name: 'Update',
value: 'update',
description: 'Update a post',
},
{
name: 'Get',
value: 'get',
description: 'Get a post',
},
{
name: 'Get All',
value: 'getAll',
description: 'Get all posts',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a post',
}, },
], ],
default: 'create', default: 'create',
@ -29,7 +49,6 @@ export const postFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* post:create */ /* post:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Title', displayName: 'Title',
name: 'title', name: 'title',
@ -69,6 +88,9 @@ export const postFields = [
displayName: 'Content', displayName: 'Content',
name: 'content', name: 'content',
type: 'string', type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '', default: '',
description: 'The content for the post', description: 'The content for the post',
}, },
@ -116,8 +138,8 @@ export const postFields = [
description: 'A named status for the post.', description: 'A named status for the post.',
}, },
{ {
displayName: 'Content Status', displayName: 'Comment Status',
name: 'contentStatus', name: 'commentStatus',
type: 'options', type: 'options',
options: [ options: [
{ {
@ -149,11 +171,60 @@ export const postFields = [
default: '', default: '',
description: 'Whether or not comments are open on the post.', description: 'Whether or not comments are open on the post.',
}, },
{
displayName: 'Format',
name: 'format',
type: 'options',
options: [
{
name: 'Standard',
value: 'standard'
},
{
name: 'Aside',
value: 'aside'
},
{
name: 'Chat',
value: 'chat'
},
{
name: 'Gallery',
value: 'gallery'
},
{
name: 'Link',
value: 'link'
},
{
name: 'Image',
value: 'image'
},
{
name: 'Quote',
value: 'quote'
},
{
name: 'Status',
value: 'status'
},
{
name: 'Video',
value: 'video'
},
{
name: 'Audio',
value: 'audio'
},
],
default: '',
description: 'Whether or not comments are open on the post.',
},
{ {
displayName: 'Sticky', displayName: 'Sticky',
name: 'sticky', name: 'sticky',
type: 'boolean', type: 'boolean',
default: '', default: false,
description: 'Whether or not the object should be treated as sticky.', description: 'Whether or not the object should be treated as sticky.',
}, },
{ {
@ -166,187 +237,574 @@ export const postFields = [
default: [], default: [],
description: 'The terms assigned to the object in the category taxonomy.', description: 'The terms assigned to the object in the category taxonomy.',
}, },
{
displayName: 'Tags',
name: 'tags',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getTags',
},
default: [],
description: 'The terms assigned to the object in the post_tag taxonomy.',
},
] ]
}, },
/* -------------------------------------------------------------------------- */
/* post:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'Post ID',
name: 'postId',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: [
'post',
],
operation: [
'update',
]
},
},
description: 'Unique identifier for the object.',
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: [
'post',
],
operation: [
'update',
],
},
},
options: [
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
description: 'The title for the post',
},
{
displayName: 'Content',
name: 'content',
type: 'string',
typeOptions: {
alwaysOpenEditWindow: true,
},
default: '',
description: 'The content for the post',
},
{
displayName: 'Slug',
name: 'slug',
type: 'string',
default: '',
description: 'An alphanumeric identifier for the object unique to its type.',
},
{
displayName: 'Password',
name: 'password',
type: 'string',
default: '',
description: 'A password to protect access to the content and excerpt.',
},
{
displayName: 'Status',
name: 'status',
type: 'options',
options: [
{
name: 'Publish',
value: 'publish'
},
{
name: 'Future',
value: 'future'
},
{
name: 'Draft',
value: 'draft'
},
{
name: 'Pending',
value: 'pending'
},
{
name: 'Private',
value: 'private'
},
],
default: '',
description: 'A named status for the post.',
},
{
displayName: 'Comment Status',
name: 'commentStatus',
type: 'options',
options: [
{
name: 'Open',
value: 'open'
},
{
name: 'Close',
value: 'closed'
},
],
default: '',
description: 'Whether or not comments are open on the post.',
},
{
displayName: 'Ping Status',
name: 'pingStatus',
type: 'options',
options: [
{
name: 'Open',
value: 'open'
},
{
name: 'Close',
value: 'closed'
},
],
default: '',
description: 'Whether or not comments are open on the post.',
},
{
displayName: 'Format',
name: 'format',
type: 'options',
options: [
{
name: 'Standard',
value: 'standard'
},
{
name: 'Aside',
value: 'aside'
},
{
name: 'Chat',
value: 'chat'
},
{
name: 'Gallery',
value: 'gallery'
},
{
name: 'Link',
value: 'link'
},
{
name: 'Image',
value: 'image'
},
{
name: 'Quote',
value: 'quote'
},
{
name: 'Status',
value: 'status'
},
{
name: 'Video',
value: 'video'
},
{
name: 'Audio',
value: 'audio'
},
],
default: '',
description: 'Whether or not comments are open on the post.',
},
{
displayName: 'Sticky',
name: 'sticky',
type: 'boolean',
default: false,
description: 'Whether or not the object should be treated as sticky.',
},
{
displayName: 'Categories',
name: 'categories',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getCategories',
},
default: [],
description: 'The terms assigned to the object in the category taxonomy.',
},
{
displayName: 'Tags',
name: 'tags',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getTags',
},
default: [],
description: 'The terms assigned to the object in the post_tag taxonomy.',
},
]
},
/* -------------------------------------------------------------------------- */
/* post:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Post ID',
name: 'postId',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: [
'post',
],
operation: [
'get',
]
},
},
description: 'Unique identifier for the object.',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
resource: [
'post',
],
operation: [
'get',
],
},
},
options: [
{
displayName: 'Password',
name: 'password',
type: 'string',
default: '',
description: 'The password for the post if it is password protected.',
},
{
displayName: 'Context',
name: 'context',
type: 'options',
options: [
{
name: 'View',
value: 'view',
},
{
name: 'Embed',
value: 'embed',
},
{
name: 'Edit',
value: 'edit',
},
],
default: 'view',
description: 'Scope under which the request is made; determines fields present in response.',
},
]
},
/* -------------------------------------------------------------------------- */
/* post:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: [
'post',
],
operation: [
'getAll',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: [
'post',
],
operation: [
'getAll',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 10,
},
default: 5,
description: 'How many results to return.',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Filter',
default: {},
displayOptions: {
show: {
resource: [
'post',
],
operation: [
'getAll',
],
},
},
options: [
{
displayName: 'Context',
name: 'context',
type: 'options',
options: [
{
name: 'View',
value: 'view',
},
{
name: 'Embed',
value: 'embed',
},
{
name: 'Edit',
value: 'edit',
},
],
default: [],
description: 'Scope under which the request is made; determines fields present in response.',
},
{
displayName: 'Order By',
name: 'orderBy',
type: 'options',
options: [
{
name: 'Author',
value: 'author',
},
{
name: 'Date',
value: 'date',
},
{
name: 'ID',
value: 'id',
},
{
name: 'ID',
value: 'id',
},
{
name: 'Include',
value: 'include',
},
{
name: 'Modified',
value: 'modified',
},
{
name: 'Parent',
value: 'parent',
},
{
name: 'Relevance',
value: 'relevance',
},
{
name: 'Slug',
value: 'slug',
},
{
name: 'Include Slugs',
value: 'includeSlugs',
},
{
name: 'Title',
value: 'title',
},
],
default: [],
description: 'Sort collection by object attribute.',
},
{
displayName: 'Order',
name: 'order',
type: 'options',
options: [
{
name: 'Desc',
value: 'desc',
},
{
name: 'Asc',
value: 'asc',
},
],
default: 'desc',
description: 'Order sort attribute ascending or descending.',
},
{
displayName: 'Search',
name: 'search',
type: 'string',
default: '',
description: 'Limit results to those matching a string.',
},
{
displayName: 'After',
name: 'after',
type: 'dateTime',
default: '',
description: 'Limit response to posts published after a given ISO8601 compliant date.',
},
{
displayName: 'Before',
name: 'before',
type: 'dateTime',
default: '',
description: 'Limit response to posts published before a given ISO8601 compliant date.',
},
{
displayName: 'Author',
name: 'author',
type: 'multiOptions',
default: [],
typeOptions: {
loadOptionsMethod: 'getAuthors',
},
description: 'Limit result set to posts assigned to specific authors.',
},
{
displayName: 'Categories',
name: 'categories',
type: 'multiOptions',
default: [],
typeOptions: {
loadOptionsMethod: 'getCategories',
},
description: 'Limit result set to all items that have the specified term assigned in the categories taxonomy.',
},
{
displayName: 'Exclude Categories',
name: 'excludedCategories',
type: 'multiOptions',
default: [],
typeOptions: {
loadOptionsMethod: 'getCategories',
},
description: 'Limit result set to all items except those that have the specified term assigned in the categories taxonomy.',
},
{
displayName: 'Tags',
name: 'tags',
type: 'multiOptions',
default: [],
typeOptions: {
loadOptionsMethod: 'getTags',
},
description: 'Limit result set to all items that have the specified term assigned in the tags taxonomy.',
},
{
displayName: 'Exclude Tags',
name: 'excludedTags',
type: 'multiOptions',
default: [],
typeOptions: {
loadOptionsMethod: 'getTags',
},
description: 'Limit result set to all items except those that have the specified term assigned in the tags taxonomy.',
},
{
displayName: 'Sticky',
name: 'sticky',
type: 'boolean',
default: false,
description: 'Limit result set to items that are sticky.',
},
/* -------------------------------------------------------------------------- */
/* user:alias */
/* -------------------------------------------------------------------------- */
{
displayName: 'ID',
name: 'id',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'alias',
] ]
}, },
}, /* -------------------------------------------------------------------------- */
description: 'The old unique identifier of the user', /* post:delete */
}, /* -------------------------------------------------------------------------- */
{ {
displayName: 'New ID', displayName: 'Post ID',
name: 'newId', name: 'postId',
type: 'string', type: 'string',
required: true, required: true,
default: '', default: '',
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'user', 'post',
],
operation: [
'alias',
]
},
},
description: 'The new unique identifier of the user',
},
/* -------------------------------------------------------------------------- */
/* user:unsubscribe */
/* -------------------------------------------------------------------------- */
{
displayName: 'ID',
name: 'id',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'unsubscribe',
]
},
},
description: 'The unique identifier of the user',
},
/* -------------------------------------------------------------------------- */
/* user:resubscribe */
/* -------------------------------------------------------------------------- */
{
displayName: 'ID',
name: 'id',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'resubscribe',
]
},
},
description: 'The unique identifier of the user',
},
/* -------------------------------------------------------------------------- */
/* user:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'ID',
name: 'id',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: [
'user',
], ],
operation: [ operation: [
'delete', 'delete',
] ]
}, },
}, },
description: 'The unique identifier of the user', description: 'Unique identifier for the object.',
}, },
/* -------------------------------------------------------------------------- */
/* user:addTags */
/* -------------------------------------------------------------------------- */
{ {
displayName: 'ID', displayName: 'Options',
name: 'id', name: 'options',
type: 'string', type: 'collection',
required: true, placeholder: 'Add Option',
default: '', default: {},
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
'user', 'post',
], ],
operation: [ operation: [
'addTags', 'delete',
] ],
}, },
}, },
description: 'The unique identifier of the user', options: [
},
{ {
displayName: 'Tags', displayName: 'Force',
name: 'tags', name: 'force',
type: 'string', type: 'boolean',
required: true, default: false,
default: '', description: 'Whether to bypass trash and force deletion.',
displayOptions: { },
show: {
resource: [
'user',
],
operation: [
'addTags',
] ]
}, },
},
description: 'Tags to add separated by ","',
},
/* -------------------------------------------------------------------------- */
/* user:removeTags */
/* -------------------------------------------------------------------------- */
{
displayName: 'ID',
name: 'id',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'removeTags',
]
},
},
description: 'The unique identifier of the user',
},
{
displayName: 'Tags',
name: 'tags',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'removeTags',
]
},
},
description: 'Tags to remove separated by ","',
},
] as INodeProperties[]; ] as INodeProperties[];

View file

@ -0,0 +1,15 @@
export interface IPost {
id?: number;
title?: string;
content?: string;
slug?: string;
password?: string;
status?: string;
comment_status?: string;
ping_status?: string;
format?: string;
sticky?: boolean;
categories?: number[];
tags?: number[];
}

View file

@ -10,12 +10,15 @@ import {
INodePropertyOptions, INodePropertyOptions,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { import {
wordpressApiRequest, wordpressApiRequest, wordpressApiRequestAllItems,
} from './GenericFunctions'; } from './GenericFunctions';
import { import {
postOperations, postOperations,
postFields, postFields,
} from './PostDescription'; } from './PostDescription';
import {
IPost,
} from './PostInterface';
export class Wordpress implements INodeType { export class Wordpress implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
@ -66,9 +69,9 @@ export class Wordpress implements INodeType {
const returnData: INodePropertyOptions[] = []; const returnData: INodePropertyOptions[] = [];
let categories; let categories;
try { try {
categories = await wordpressApiRequest.call(this, 'GET', '/categories', {}); categories = await wordpressApiRequestAllItems.call(this, 'GET', '/categories', {});
} catch (err) { } catch (err) {
throw new Error(`Mandrill Error: ${err}`); throw new Error(`Wordpress Error: ${err}`);
} }
for (const category of categories) { for (const category of categories) {
const categoryName = category.name; const categoryName = category.name;
@ -79,19 +82,54 @@ export class Wordpress implements INodeType {
value: categoryId, value: categoryId,
}); });
} }
return returnData; return returnData;
},
// Get all the available tags to display them to user so that he can
// select them easily
async getTags(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
let tags;
try {
tags = await wordpressApiRequestAllItems.call(this, 'GET', '/tags', {});
} catch (err) {
throw new Error(`Wordpress Error: ${err}`);
} }
for (const tag of tags) {
const tagName = tag.name;
const tagId = tag.id;
returnData.push({
name: tagName,
value: tagId,
});
}
return returnData;
},
// Get all the available authors to display them to user so that he can
// select them easily
async getAuthors(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
let authors;
try {
authors = await wordpressApiRequestAllItems.call(this, 'GET', '/users', {}, { who: 'authors' });
} catch (err) {
throw new Error(`Wordpress Error: ${err}`);
}
for (const author of authors) {
const authorName = author.name;
const authorId = author.id;
returnData.push({
name: authorName,
value: authorId,
});
}
return returnData;
},
}, },
}; };
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> { async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const credentials = this.getCredentials('flowApi');
if (credentials === undefined) {
throw new Error('No credentials got returned!');
}
const items = this.getInputData(); const items = this.getInputData();
const returnData: IDataObject[] = []; const returnData: IDataObject[] = [];
const length = items.length as unknown as number; const length = items.length as unknown as number;
@ -100,203 +138,182 @@ export class Wordpress implements INodeType {
const resource = this.getNodeParameter('resource', 0) as string; const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string; const operation = this.getNodeParameter('operation', 0) as string;
// for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
// if (resource === 'task') { if (resource === 'post') {
// //https://developer.getflow.com/api/#tasks_create-task //https://developer.wordpress.org/rest-api/reference/posts/#create-a-post
// if (operation === 'create') { if (operation === 'create') {
// const workspaceId = this.getNodeParameter('workspaceId', i) as string; const title = this.getNodeParameter('title', i) as string;
// const name = this.getNodeParameter('name', i) as string; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
// const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const body: IPost = {
// const body: ITask = { title,
// organization_id: credentials.organizationId as number, };
// }; if (additionalFields.content) {
// const task: TaskInfo = { body.content = additionalFields.content as string;
// name, }
// workspace_id: parseInt(workspaceId, 10) if (additionalFields.slug) {
// }; body.slug = additionalFields.slug as string;
// if (additionalFields.ownerId) { }
// task.owner_id = parseInt(additionalFields.ownerId as string, 10); if (additionalFields.password) {
// } body.password = additionalFields.password as string;
// if (additionalFields.listId) { }
// task.list_id = parseInt(additionalFields.listId as string, 10); if (additionalFields.status) {
// } body.status = additionalFields.status as string;
// if (additionalFields.startsOn) { }
// task.starts_on = additionalFields.startsOn as string; if (additionalFields.commentStatus) {
// } body.comment_status = additionalFields.commentStatus as string;
// if (additionalFields.dueOn) { }
// task.due_on = additionalFields.dueOn as string; if (additionalFields.pingStatus) {
// } body.ping_status = additionalFields.pingStatus as string;
// if (additionalFields.mirrorParentSubscribers) { }
// task.mirror_parent_subscribers = additionalFields.mirrorParentSubscribers as boolean; if (additionalFields.sticky) {
// } body.sticky = additionalFields.sticky as boolean;
// if (additionalFields.mirrorParentTags) { }
// task.mirror_parent_tags = additionalFields.mirrorParentTags as boolean; if (additionalFields.categories) {
// } body.categories = additionalFields.categories as number[];
// if (additionalFields.noteContent) { }
// task.note_content = additionalFields.noteContent as string; if (additionalFields.tags) {
// } body.tags = additionalFields.tags as number[];
// if (additionalFields.noteMimeType) { }
// task.note_mime_type = additionalFields.noteMimeType as string; if (additionalFields.format) {
// } body.format = additionalFields.format as string;
// if (additionalFields.parentId) { }
// task.parent_id = parseInt(additionalFields.parentId as string, 10); try{
// } responseData = await wordpressApiRequest.call(this, 'POST', '/posts', body);
// if (additionalFields.positionList) { } catch (err) {
// task.position_list = additionalFields.positionList as number; throw new Error(`Wordpress Error: ${err.message}`);
// } }
// if (additionalFields.positionUpcoming) { }
// task.position_upcoming = additionalFields.positionUpcoming as number; //https://developer.wordpress.org/rest-api/reference/posts/#update-a-post
// } if (operation === 'update') {
// if (additionalFields.position) { const postId = this.getNodeParameter('postId', i) as string;
// task.position = additionalFields.position as number; const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
// } const body: IPost = {
// if (additionalFields.sectionId) { id: parseInt(postId, 10),
// task.section_id = additionalFields.sectionId as number; };
// } if (updateFields.title) {
// if (additionalFields.tags) { body.title = updateFields.title as string;
// task.tags = (additionalFields.tags as string).split(','); }
// } if (updateFields.content) {
// body.task = task; body.content = updateFields.content as string;
// try { }
// responseData = await flowApiRequest.call(this, 'POST', '/tasks', body); if (updateFields.slug) {
// responseData = responseData.task; body.slug = updateFields.slug as string;
// } catch (err) { }
// throw new Error(`Flow Error: ${err.message}`); if (updateFields.password) {
// } body.password = updateFields.password as string;
// } }
// //https://developer.getflow.com/api/#tasks_update-a-task if (updateFields.status) {
// if (operation === 'update') { body.status = updateFields.status as string;
// const workspaceId = this.getNodeParameter('workspaceId', i) as string; }
// const taskId = this.getNodeParameter('taskId', i) as string; if (updateFields.commentStatus) {
// const updateFields = this.getNodeParameter('updateFields', i) as IDataObject; body.comment_status = updateFields.commentStatus as string;
// const body: ITask = { }
// organization_id: credentials.organizationId as number, if (updateFields.pingStatus) {
// }; body.ping_status = updateFields.pingStatus as string;
// const task: TaskInfo = { }
// workspace_id: parseInt(workspaceId, 10), if (updateFields.sticky) {
// id: parseInt(taskId, 10), body.sticky = updateFields.sticky as boolean;
// }; }
// if (updateFields.name) { if (updateFields.categories) {
// task.name = updateFields.name as string; body.categories = updateFields.categories as number[];
// } }
// if (updateFields.ownerId) { if (updateFields.tags) {
// task.owner_id = parseInt(updateFields.ownerId as string, 10); body.tags = updateFields.tags as number[];
// } }
// if (updateFields.listId) { if (updateFields.format) {
// task.list_id = parseInt(updateFields.listId as string, 10); body.format = updateFields.format as string;
// } }
// if (updateFields.startsOn) { try {
// task.starts_on = updateFields.startsOn as string; responseData = await wordpressApiRequest.call(this, 'POST', `/posts/${postId}`, body);
// } } catch (err) {
// if (updateFields.dueOn) { throw new Error(`Wordpress Error: ${err.message}`);
// task.due_on = updateFields.dueOn as string; }
// } }
// if (updateFields.mirrorParentSubscribers) { //https://developer.wordpress.org/rest-api/reference/posts/#retrieve-a-post
// task.mirror_parent_subscribers = updateFields.mirrorParentSubscribers as boolean; if (operation === 'get') {
// } const postId = this.getNodeParameter('postId', i) as string;
// if (updateFields.mirrorParentTags) { const options = this.getNodeParameter('options', i) as IDataObject;
// task.mirror_parent_tags = updateFields.mirrorParentTags as boolean; options.id = postId;
// } if (options.password) {
// if (updateFields.noteContent) { qs.password = options.password as string;
// task.note_content = updateFields.noteContent as string; }
// } if (options.context) {
// if (updateFields.noteMimeType) { qs.context = options.context as string;
// task.note_mime_type = updateFields.noteMimeType as string; }
// } try {
// if (updateFields.parentId) { responseData = await wordpressApiRequest.call(this,'GET', `/posts/${postId}`, {}, qs);
// task.parent_id = parseInt(updateFields.parentId as string, 10); } catch (err) {
// } throw new Error(`Wordpress Error: ${err.message}`);
// if (updateFields.positionList) { }
// task.position_list = updateFields.positionList as number; }
// } //https://developer.wordpress.org/rest-api/reference/posts/#list-posts
// if (updateFields.positionUpcoming) { if (operation === 'getAll') {
// task.position_upcoming = updateFields.positionUpcoming as number; const returnAll = this.getNodeParameter('returnAll', i) as boolean;
// } const filters = this.getNodeParameter('filters', i) as IDataObject;
// if (updateFields.position) { if (filters.context) {
// task.position = updateFields.position as number; qs.context = filters.context as string;
// } }
// if (updateFields.sectionId) { if (filters.orderBy) {
// task.section_id = updateFields.sectionId as number; qs.orderby = filters.orderBy as string;
// } }
// if (updateFields.tags) { if (filters.order) {
// task.tags = (updateFields.tags as string).split(','); qs.order = filters.order as string;
// } }
// if (updateFields.completed) { if (filters.search) {
// task.completed = updateFields.completed as boolean; qs.search = filters.search as string;
// } }
// body.task = task; if (filters.after) {
// try { qs.after = filters.after as string;
// responseData = await flowApiRequest.call(this, 'PUT', `/tasks/${taskId}`, body); }
// responseData = responseData.task; if (filters.author) {
// } catch (err) { qs.author = filters.author as number[];
// throw new Error(`Flow Error: ${err.message}`); }
// } if (filters.categories) {
// } qs.categories = filters.categories as number[];
// //https://developer.getflow.com/api/#tasks_get-task }
// if (operation === 'get') { if (filters.excludedCategories) {
// const taskId = this.getNodeParameter('taskId', i) as string; qs.categories_exclude = filters.excludedCategories as number[];
// const filters = this.getNodeParameter('filters', i) as IDataObject; }
// qs.organization_id = credentials.organizationId as number; if (filters.tags) {
// if (filters.include) { qs.tags = filters.tags as number[];
// qs.include = (filters.include as string[]).join(','); }
// } if (filters.excludedTags) {
// try { qs.tags_exclude = filters.excludedTags as number[];
// responseData = await flowApiRequest.call(this,'GET', `/tasks/${taskId}`, {}, qs); }
// } catch (err) { if (filters.sticky) {
// throw new Error(`Flow Error: ${err.message}`); qs.sticky = filters.sticky as boolean;
// } }
// } try {
// //https://developer.getflow.com/api/#tasks_get-tasks if (returnAll === true) {
// if (operation === 'getAll') { responseData = await wordpressApiRequestAllItems.call(this, 'GET', '/posts', {}, qs);
// const returnAll = this.getNodeParameter('returnAll', i) as boolean; } else {
// const filters = this.getNodeParameter('filters', i) as IDataObject; qs.per_page = this.getNodeParameter('limit', i) as number;
// qs.organization_id = credentials.organizationId as number; responseData = await wordpressApiRequest.call(this, 'GET', '/posts', {}, qs);
// if (filters.include) { }
// qs.include = (filters.include as string[]).join(','); } catch (err) {
// } throw new Error(`Wordpress Error: ${err.message}`);
// if (filters.order) { }
// qs.order = filters.order as string; }
// } //https://developer.wordpress.org/rest-api/reference/posts/#delete-a-post
// if (filters.workspaceId) { if (operation === 'delete') {
// qs.workspace_id = filters.workspaceId as string; const postId = this.getNodeParameter('postId', i) as string;
// } const options = this.getNodeParameter('options', i) as IDataObject;
// if (filters.createdBefore) { if (options.force) {
// qs.created_before = filters.createdBefore as string; qs.force = options.force as boolean;
// } }
// if (filters.createdAfter) { try {
// qs.created_after = filters.createdAfter as string; responseData = await wordpressApiRequest.call(this, 'DELETE', `/posts/${postId}`, {}, qs);
// } } catch (err) {
// if (filters.updateBefore) { throw new Error(`Wordpress Error: ${err.message}`);
// qs.updated_before = filters.updateBefore as string; }
// } }
// if (filters.updateAfter) { }
// qs.updated_after = filters.updateAfter as string; if (Array.isArray(responseData)) {
// } returnData.push.apply(returnData, responseData as IDataObject[]);
// if (filters.deleted) { } else {
// qs.deleted = filters.deleted as boolean; returnData.push(responseData as IDataObject);
// } }
// if (filters.cleared) { }
// qs.cleared = filters.cleared as boolean;
// }
// try {
// if (returnAll === true) {
// responseData = await FlowApiRequestAllItems.call(this, 'tasks', 'GET', '/tasks', {}, qs);
// } else {
// qs.limit = this.getNodeParameter('limit', i) as number;
// responseData = await flowApiRequest.call(this, 'GET', '/tasks', {}, qs);
// responseData = responseData.tasks;
// }
// } catch (err) {
// throw new Error(`Flow Error: ${err.message}`);
// }
// }
// }
// if (Array.isArray(responseData)) {
// returnData.push.apply(returnData, responseData as IDataObject[]);
// } else {
// returnData.push(responseData as IDataObject);
// }
// }
return [this.helpers.returnJsonArray(returnData)]; return [this.helpers.returnJsonArray(returnData)];
} }
} }