Fix postComment:getAll

This commit is contained in:
Iván Ovejero 2021-01-29 18:47:43 -03:00
parent 19d11664e6
commit 3545303a3b
4 changed files with 58 additions and 8 deletions

View file

@ -23,6 +23,7 @@ export async function redditApiRequest(
): Promise<any> { // tslint:disable-line:no-any
const resource = this.getNodeParameter('resource', 0) as string;
const authRequired = ['profile', 'post', 'postComment'].includes(resource);
const options: OptionsWithUri = {
@ -40,7 +41,7 @@ export async function redditApiRequest(
}
try {
console.log(options);
// console.log(options);
return authRequired
? await this.helpers.requestOAuth2.call(this, 'redditOAuth2Api', options)
: await this.helpers.request.call(this, options);
@ -68,16 +69,21 @@ export async function redditApiRequestAllItems(
let responseData;
const returnData: IDataObject[] = [];
const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
do {
console.log(method);
console.log(endpoint);
console.log(qs);
// console.log(method);
// console.log(endpoint);
// console.log(qs);
responseData = await redditApiRequest.call(this, method, endpoint, qs);
console.log(responseData);
qs.after = responseData.after;
if (endpoint === 'api/search_subreddits.json') {
responseData.subreddits.forEach((child: any) => returnData.push(child)); // tslint:disable-line:no-any
} else if (resource === 'postComment' && operation === 'getAll') {
responseData[1].data.children.forEach((child: any) => returnData.push(child.data)); // tslint:disable-line:no-any
} else {
responseData.data.children.forEach((child: any) => returnData.push(child.data)); // tslint:disable-line:no-any
}

View file

@ -122,6 +122,47 @@ export const postCommentFields = [
},
},
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
default: false,
description: 'Return all results.',
displayOptions: {
show: {
resource: [
'postComment',
],
operation: [
'getAll',
],
},
},
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
default: 5,
description: 'The number of results to return.',
typeOptions: {
minValue: 1,
maxValue: 100,
},
displayOptions: {
show: {
resource: [
'postComment',
],
operation: [
'getAll',
],
returnAll: [
false,
],
},
},
},
// ----------------------------------
// postComment: delete
// ----------------------------------

View file

@ -18,7 +18,7 @@ export const postOperations = [
{
name: 'Delete',
value: 'delete',
description: 'Withdraw a post from a subreddit.',
description: 'Delete a post from a subreddit.',
},
{
name: 'Get',

View file

@ -96,7 +96,7 @@ export class Reddit implements INodeType {
value: 'user',
},
],
default: 'comment',
default: 'post',
description: 'Resource to consume',
},
...postCommentOperations,
@ -152,6 +152,7 @@ export class Reddit implements INodeType {
}
responseData = await redditApiRequest.call(this, 'POST', 'api/submit', qs);
delete responseData.jquery;
// ----------------------------------
// post: delete
@ -237,8 +238,10 @@ export class Reddit implements INodeType {
const postId = this.getNodeParameter('postId', i) as string;
const endpoint = `r/${subreddit}/comments/${postId}.json`;
responseData = await redditApiRequest.call(this, 'GET', endpoint, {});
responseData = responseData[1].data.children.map((child: any) => child.data); // tslint:disable-line:no-any
responseData = await handleListing.call(this, i, endpoint);
// console.log(responseData);
// responseData = await redditApiRequest.call(this, 'GET', endpoint, {});
// responseData = responseData[1].data.children.map((child: any) => child.data); // tslint:disable-line:no-any
} else if (operation === 'remove') {