diff --git a/packages/backend/src/helpers/global-variable/connection.ts b/packages/backend/src/helpers/global-variable/connection.ts index 5143c865..491b402e 100644 --- a/packages/backend/src/helpers/global-variable/connection.ts +++ b/packages/backend/src/helpers/global-variable/connection.ts @@ -1,25 +1,36 @@ -import HttpClient from '../http-client'; +import createHttpClient from '../http-client'; import Connection from '../../models/connection'; import { IJSONObject, IApp } from '@automatisch/types'; +import { AxiosInstance as IHttpClient } from 'axios'; + +type IGlobalVariableForConnection = { + auth: { + set: (args: IJSONObject) => Promise; + }; + app: IApp; + http: IHttpClient; +}; const prepareGlobalVariableForConnection = ( connection: Connection, appData: IApp -) => { +): IGlobalVariableForConnection => { return { auth: { set: async (args: IJSONObject) => { - await connection.$query().patchAndFetch({ + const persistedConnection = await connection.$query().patchAndFetch({ formattedData: { ...connection.formattedData, ...args, }, }); + + return persistedConnection; }, ...connection.formattedData, }, app: appData, - http: new HttpClient({ baseURL: appData.baseUrl }), + http: createHttpClient({ baseURL: appData.baseUrl }), }; };