refactor: Use new error handling structure for user tweets
This commit is contained in:
@@ -1,8 +1,4 @@
|
|||||||
import {
|
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||||
IGlobalVariable,
|
|
||||||
IJSONObject,
|
|
||||||
ITriggerOutput,
|
|
||||||
} from '@automatisch/types';
|
|
||||||
import { URLSearchParams } from 'url';
|
import { URLSearchParams } from 'url';
|
||||||
import omitBy from 'lodash/omitBy';
|
import omitBy from 'lodash/omitBy';
|
||||||
import isEmpty from 'lodash/isEmpty';
|
import isEmpty from 'lodash/isEmpty';
|
||||||
@@ -18,10 +14,6 @@ const fetchTweets = async ($: IGlobalVariable, username: string) => {
|
|||||||
|
|
||||||
let response;
|
let response;
|
||||||
|
|
||||||
const tweets: ITriggerOutput = {
|
|
||||||
data: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
const params: IJSONObject = {
|
const params: IJSONObject = {
|
||||||
since_id: $.execution.testRun ? null : $.flow.lastInternalId,
|
since_id: $.execution.testRun ? null : $.flow.lastInternalId,
|
||||||
@@ -36,14 +28,9 @@ const fetchTweets = async ($: IGlobalVariable, username: string) => {
|
|||||||
|
|
||||||
response = await $.http.get(requestPath);
|
response = await $.http.get(requestPath);
|
||||||
|
|
||||||
if (response.httpError) {
|
|
||||||
tweets.error = response.httpError;
|
|
||||||
return tweets;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.data.meta.result_count > 0) {
|
if (response.data.meta.result_count > 0) {
|
||||||
response.data.data.forEach((tweet: IJSONObject) => {
|
response.data.data.forEach((tweet: IJSONObject) => {
|
||||||
tweets.data.push({
|
$.output.data.push({
|
||||||
raw: tweet,
|
raw: tweet,
|
||||||
meta: {
|
meta: {
|
||||||
internalId: tweet.id as string,
|
internalId: tweet.id as string,
|
||||||
@@ -53,7 +40,7 @@ const fetchTweets = async ($: IGlobalVariable, username: string) => {
|
|||||||
}
|
}
|
||||||
} while (response.data.meta.next_token && !$.execution.testRun);
|
} while (response.data.meta.next_token && !$.execution.testRun);
|
||||||
|
|
||||||
return tweets;
|
return $.output;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getUserTweets = async (
|
const getUserTweets = async (
|
||||||
@@ -69,13 +56,7 @@ const getUserTweets = async (
|
|||||||
username = $.step.parameters.username as string;
|
username = $.step.parameters.username as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tweets = await fetchTweets($, username);
|
await fetchTweets($, username);
|
||||||
|
|
||||||
tweets.data.sort((tweet, nextTweet) => {
|
|
||||||
return Number(tweet.meta.internalId) - Number(nextTweet.meta.internalId);
|
|
||||||
});
|
|
||||||
|
|
||||||
return tweets;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default getUserTweets;
|
export default getUserTweets;
|
||||||
|
@@ -36,7 +36,7 @@ export default defineTrigger({
|
|||||||
|
|
||||||
sort($) {
|
sort($) {
|
||||||
$.output.data.sort((tweet, nextTweet) => {
|
$.output.data.sort((tweet, nextTweet) => {
|
||||||
return Number(tweet.meta.internalId) - Number(nextTweet.meta.internalId);
|
return Number(nextTweet.meta.internalId) - Number(tweet.meta.internalId);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@@ -34,4 +34,10 @@ export default defineTrigger({
|
|||||||
currentUser: false,
|
currentUser: false,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sort($) {
|
||||||
|
$.output.data.sort((tweet, nextTweet) => {
|
||||||
|
return Number(nextTweet.meta.internalId) - Number(tweet.meta.internalId);
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user