diff --git a/packages/backend/src/controllers/api/v1/connections/reset-connection.js b/packages/backend/src/controllers/api/v1/connections/reset-connection.js index e86bd5df..2d7fa6a6 100644 --- a/packages/backend/src/controllers/api/v1/connections/reset-connection.js +++ b/packages/backend/src/controllers/api/v1/connections/reset-connection.js @@ -8,11 +8,7 @@ export default async (request, response) => { }) .throwIfNotFound(); - connection = await connection.$query().patchAndFetch({ - formattedData: connection?.formattedData?.screenName - ? { screenName: connection.formattedData.screenName } - : null, - }); + connection = await connection.reset(); renderObject(response, connection); }; diff --git a/packages/backend/src/graphql/mutation-resolvers.js b/packages/backend/src/graphql/mutation-resolvers.js index f4aa8de0..4d33ccf3 100644 --- a/packages/backend/src/graphql/mutation-resolvers.js +++ b/packages/backend/src/graphql/mutation-resolvers.js @@ -1,6 +1,5 @@ import createUser from './mutations/create-user.ee.js'; import duplicateFlow from './mutations/duplicate-flow.js'; -import resetConnection from './mutations/reset-connection.js'; import updateConnection from './mutations/update-connection.js'; import updateFlowStatus from './mutations/update-flow-status.js'; import updateStep from './mutations/update-step.js'; @@ -16,6 +15,7 @@ import updateCurrentUser from './mutations/update-current-user.js'; import generateAuthUrl from './mutations/generate-auth-url.js'; import createConnection from './mutations/create-connection.js'; import deleteFlow from './mutations/delete-flow.js'; +import resetConnection from './mutations/reset-connection.js'; const mutationResolvers = { createConnection, diff --git a/packages/backend/src/models/connection.js b/packages/backend/src/models/connection.js index f3f046dc..aa1f5dd6 100644 --- a/packages/backend/src/models/connection.js +++ b/packages/backend/src/models/connection.js @@ -249,6 +249,18 @@ class Connection extends Base { return { url }; } + + async reset() { + const formattedData = this?.formattedData?.screenName + ? { screenName: this.formattedData.screenName } + : null; + + const updatedConnection = await this.$query().patchAndFetch({ + formattedData, + }); + + return updatedConnection; + } } export default Connection;