Skip to content

Commit

Permalink
feat(Wordpress Node): Add Status option to Get All operation of Posts…
Browse files Browse the repository at this point in the history
… resource

* Wordpress: Add status to getAll: post

* Fix status name used in query string

* Alphabetically order options for getAll: post

* 🐛 Fixed pagination issue when there is no posts for the status

* ✨ Updated password field to use a password type

Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com>
  • Loading branch information
that-one-tom and Joffcom committed Mar 13, 2022
1 parent 535dfe0 commit 4d4db7f
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 75 deletions.
3 changes: 3 additions & 0 deletions packages/nodes-base/credentials/WordpressApi.credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export class WordpressApi implements ICredentialType {
displayName: 'Password',
name: 'password',
type: 'string',
typeOptions: {
password: true,
},
default: '',
},
{
Expand Down
1 change: 1 addition & 0 deletions packages/nodes-base/nodes/Wordpress/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export async function wordpressApiRequestAllItems(this: IExecuteFunctions | ILoa
returnData.push.apply(returnData, responseData.body);
} while (
responseData.headers['x-wp-totalpages'] !== undefined &&
responseData.headers['x-wp-totalpages'] !== '0' &&
parseInt(responseData.headers['x-wp-totalpages'], 10) !== query.page
);

Expand Down
178 changes: 103 additions & 75 deletions packages/nodes-base/nodes/Wordpress/PostDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,40 @@ export const postFields: INodeProperties[] = [
},
},
options: [
{
displayName: 'After',
name: 'after',
type: 'dateTime',
default: '',
description: 'Limit response to posts published after 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: 'Before',
name: 'before',
type: 'dateTime',
default: '',
description: 'Limit response to posts published before a given ISO8601 compliant date.',
},
{
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: 'Context',
name: 'context',
Expand All @@ -629,6 +663,43 @@ export const postFields: INodeProperties[] = [
default: 'view',
description: 'Scope under which the request is made; determines fields present in response.',
},
{
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: '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: 'Order',
name: 'order',
type: 'options',
options: [
{
name: 'ASC',
value: 'asc',
},
{
name: 'DESC',
value: 'desc',
},
],
default: 'desc',
description: 'Order sort attribute ascending or descending.',
},
{
displayName: 'Order By',
name: 'orderBy',
Expand Down Expand Up @@ -678,23 +749,6 @@ export const postFields: INodeProperties[] = [
default: 'id',
description: 'Sort collection by object attribute.',
},
{
displayName: 'Order',
name: 'order',
type: 'options',
options: [
{
name: 'ASC',
value: 'asc',
},
{
name: 'DESC',
value: 'desc',
},
],
default: 'desc',
description: 'Order sort attribute ascending or descending.',
},
{
displayName: 'Search',
name: 'search',
Expand All @@ -703,48 +757,40 @@ export const postFields: INodeProperties[] = [
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: 'Status',
name: 'status',
type: 'options',
options: [
{
name: 'Draft',
value: 'draft',
},
{
name: 'Future',
value: 'future',
},
{
name: 'Pending',
value: 'pending',
},
{
name: 'Private',
value: 'private',
},
{
name: 'Publish',
value: 'publish',
},
],
default: 'publish',
description: 'The status of the post.',
},
{
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: 'Sticky',
name: 'sticky',
type: 'boolean',
default: false,
description: 'Limit result set to items that are sticky.',
},
{
displayName: 'Tags',
Expand All @@ -756,24 +802,6 @@ export const postFields: INodeProperties[] = [
},
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.',
},

],
},
/* -------------------------------------------------------------------------- */
Expand Down
3 changes: 3 additions & 0 deletions packages/nodes-base/nodes/Wordpress/Wordpress.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ export class Wordpress implements INodeType {
if (options.sticky) {
qs.sticky = options.sticky as boolean;
}
if (options.status) {
qs.status = options.status as string;
}
if (returnAll === true) {
responseData = await wordpressApiRequestAllItems.call(this, 'GET', '/posts', {}, qs);
} else {
Expand Down

0 comments on commit 4d4db7f

Please sign in to comment.