From db2c3556de597ed330dde055f271eab56c3e55eb Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Wed, 31 Aug 2022 12:47:45 +0300 Subject: [PATCH] refactor: Get last execution and find last internal ID --- .../src/apps/twitter/client/endpoints/get-user-tweets.ts | 4 +--- packages/backend/src/models/flow.ts | 9 +++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/apps/twitter/client/endpoints/get-user-tweets.ts b/packages/backend/src/apps/twitter/client/endpoints/get-user-tweets.ts index c9619dfb..b6343ced 100644 --- a/packages/backend/src/apps/twitter/client/endpoints/get-user-tweets.ts +++ b/packages/backend/src/apps/twitter/client/endpoints/get-user-tweets.ts @@ -26,9 +26,7 @@ export default class GetUserTweets { pagination_token: response?.data?.meta?.next_token, }; - const queryParams = new URLSearchParams({ - ...omitBy(params, isEmpty), - }); + const queryParams = new URLSearchParams(omitBy(params, isEmpty)); const requestPath = `/2/users/${userId}/tweets${ queryParams.toString() ? `?${queryParams.toString()}` : '' diff --git a/packages/backend/src/models/flow.ts b/packages/backend/src/models/flow.ts index 9cf31cad..ca44c208 100644 --- a/packages/backend/src/models/flow.ts +++ b/packages/backend/src/models/flow.ts @@ -4,6 +4,7 @@ import Base from './base'; import Step from './step'; import Execution from './execution'; import Telemetry from '../helpers/telemetry'; +import { IExecution } from '@automatisch/types'; class Flow extends Base { id!: string; @@ -50,11 +51,11 @@ class Flow extends Base { }); async lastInternalId() { - const lastInternalIdFetched: any = await this.$relatedQuery( - 'executions' - ).max('internal_id'); + const lastExecution = await this.$relatedQuery('executions') + .orderBy('created_at', 'desc') + .first(); - return lastInternalIdFetched[0].max; + return (lastExecution as Execution).internalId; } async $beforeUpdate(