fix/cleanup(server/twitter): Fix for fetch after tweet & gen cleanup

This commit is contained in:
Taso authored and Taso committed 2021-03-16 16:24:27 -04:00
1 parent 3031e650e3
commit 1a9c21f89d
1 file changed
+12 -10
+12 -10
View File
@@ -95,6 +95,7 @@ async function fetchTweetsFiltered(profileId: number, searchValue: string): Prom
/** /**
* Retrieve a Tweet by ID * Retrieve a Tweet by ID
* @param profileId Unique id for the twitter profile (NOT user identifier)
* @param tweetId - primary key of the tweet ID * @param tweetId - primary key of the tweet ID
*/ */
async function getTweet(profileId: number, tweetId: number): Promise<Tweet> { async function getTweet(profileId: number, tweetId: number): Promise<Tweet> {
@@ -131,8 +132,8 @@ async function createTweet(identifier: string, tweet: NewTweet): Promise<Tweet>
tweet.images, tweet.images,
tweet.retweet, tweet.retweet,
]); ]);
const insertData = <any>results; const insertData = <Tweet[]>results;
return await getTweet(profile.id, insertData.insertId); return await getTweet(profile.id, insertData[0].id);
} }
async function createTweetReport(tweetId: number, profileId: number): Promise<void> { async function createTweetReport(tweetId: number, profileId: number): Promise<void> {
@@ -189,7 +190,8 @@ async function createDefaultProfile(identifier: string): Promise<Profile> {
INSERT INTO npwd_twitter_profiles (identifier, profile_name) INSERT INTO npwd_twitter_profiles (identifier, profile_name)
VALUES (?, ?) VALUES (?, ?)
`; `;
const [result] = await pool.execute(query, [identifier, profileName]);
await pool.execute(query, [identifier, profileName]);
return getProfile(identifier); return getProfile(identifier);
} }
@@ -251,7 +253,7 @@ async function deleteTweet(identifier: string, tweetId: number): Promise<void> {
DELETE FROM npwd_twitter_tweets DELETE FROM npwd_twitter_tweets
WHERE identifier = ? AND id = ? WHERE identifier = ? AND id = ?
`; `;
const [result] = await pool.execute(query, [identifier, tweetId]); await pool.execute(query, [identifier, tweetId]);
} }
/** /**
@@ -428,11 +430,10 @@ onNet(events.TWITTER_RETWEET, async (tweetId: number) => {
// alert the player that they have already retweeted // alert the player that they have already retweeted
// this post (or that they are the original poster) // this post (or that they are the original poster)
if (await doesRetweetExist(tweetId, identifier)) { if (await doesRetweetExist(tweetId, identifier)) {
emitNet(events.TWITTER_RETWEET_EXISTS, _source, { return emitNet(events.TWITTER_RETWEET_EXISTS, _source, {
message: 'TWITTER_RETWEET_EXISTS', message: 'TWITTER_RETWEET_EXISTS',
type: 'error', type: 'error',
}); });
return;
} }
// our message for this row is blank because when we // our message for this row is blank because when we
@@ -460,13 +461,14 @@ onNet(events.TWITTER_REPORT, async (tweetId: number) => {
const tweet = await getTweet(profile.id, tweetId); const tweet = await getTweet(profile.id, tweetId);
const reportExists = await doesReportExist(tweet.id, profile.id); const reportExists = await doesReportExist(tweet.id, profile.id);
if (reportExists) { if (reportExists) {
twitterLogger.warn('This profile has already reported this tweet'); return twitterLogger.warn('This profile has already reported this tweet');
} else {
await createTweetReport(tweet.id, profile.id);
await reportTweetToDiscord(tweet, profile);
} }
await createTweetReport(tweet.id, profile.id);
await reportTweetToDiscord(tweet, profile);
emitNet(events.TWITTER_REPORT_SUCCESS, _source); emitNet(events.TWITTER_REPORT_SUCCESS, _source);
} catch (e) { } catch (e) {
emitNet(events.TWITTER_REPORT_FAILURE, _source); emitNet(events.TWITTER_REPORT_FAILURE, _source);