chore: Add the type for global variable of connection

This commit is contained in:
Faruk AYDIN
2022-10-04 04:14:48 +03:00
parent 4d5be952ce
commit 67cb57e7ac

View File

@@ -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<Connection>;
};
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 }),
};
};