chore: Add the type for global variable of connection
This commit is contained in:
@@ -1,25 +1,36 @@
|
|||||||
import HttpClient from '../http-client';
|
import createHttpClient from '../http-client';
|
||||||
import Connection from '../../models/connection';
|
import Connection from '../../models/connection';
|
||||||
import { IJSONObject, IApp } from '@automatisch/types';
|
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 = (
|
const prepareGlobalVariableForConnection = (
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
appData: IApp
|
appData: IApp
|
||||||
) => {
|
): IGlobalVariableForConnection => {
|
||||||
return {
|
return {
|
||||||
auth: {
|
auth: {
|
||||||
set: async (args: IJSONObject) => {
|
set: async (args: IJSONObject) => {
|
||||||
await connection.$query().patchAndFetch({
|
const persistedConnection = await connection.$query().patchAndFetch({
|
||||||
formattedData: {
|
formattedData: {
|
||||||
...connection.formattedData,
|
...connection.formattedData,
|
||||||
...args,
|
...args,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return persistedConnection;
|
||||||
},
|
},
|
||||||
...connection.formattedData,
|
...connection.formattedData,
|
||||||
},
|
},
|
||||||
app: appData,
|
app: appData,
|
||||||
http: new HttpClient({ baseURL: appData.baseUrl }),
|
http: createHttpClient({ baseURL: appData.baseUrl }),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user