Flatten responses for profile:get

This commit is contained in:
Iván Ovejero 2021-01-29 18:52:33 -03:00
parent 3545303a3b
commit 50b5305a9c
2 changed files with 11 additions and 9 deletions

View file

@ -41,7 +41,6 @@ export async function redditApiRequest(
}
try {
// console.log(options);
return authRequired
? await this.helpers.requestOAuth2.call(this, 'redditOAuth2Api', options)
: await this.helpers.request.call(this, options);
@ -73,11 +72,7 @@ export async function redditApiRequestAllItems(
const operation = this.getNodeParameter('operation', 0) as string;
do {
// 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') {

View file

@ -234,14 +234,13 @@ export class Reddit implements INodeType {
} else if (operation === 'getAll') {
// https://www.reddit.com/r/{subrreddit}/comments/{postId}.json
const subreddit = this.getNodeParameter('subreddit', i);
const postId = this.getNodeParameter('postId', i) as string;
const endpoint = `r/${subreddit}/comments/${postId}.json`;
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') {
@ -306,6 +305,12 @@ export class Reddit implements INodeType {
if (details === 'identity') {
responseData = responseData.features;
} else if (details === 'friends') {
responseData = responseData.data.children;
} else if (details === 'karma') {
responseData = responseData.data;
} else if (details === 'trophies') {
responseData = responseData.data.trophies.map((trophy: IDataObject) => trophy.data);
}
}
@ -395,7 +400,9 @@ export class Reddit implements INodeType {
? await redditApiRequest.call(this, 'GET', endpoint, {})
: await handleListing.call(this, i, endpoint);
if (details === 'about') {
if (details === 'gilded') {
responseData = responseData.data.children;
} else if (details === 'about') {
responseData = responseData.data;
}