fix: Introduce formattedData for connections to separate types
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
39b50fc0d3
commit
719a948134
@@ -22,15 +22,15 @@ const createAuthDataResolver = async (
|
||||
const appData = App.findOneByKey(connection.key);
|
||||
|
||||
const appInstance = new appClass(appData, {
|
||||
consumerKey: connection.data.consumerKey,
|
||||
consumerSecret: connection.data.consumerSecret,
|
||||
consumerKey: connection.formattedData.consumerKey,
|
||||
consumerSecret: connection.formattedData.consumerSecret,
|
||||
});
|
||||
|
||||
const authLink = await appInstance.authenticationClient.createAuthData();
|
||||
|
||||
await connection.$query().patch({
|
||||
data: {
|
||||
...connection.data,
|
||||
formattedData: {
|
||||
...connection.formattedData,
|
||||
...authLink,
|
||||
},
|
||||
});
|
||||
|
@@ -4,10 +4,11 @@ import connectionType from '../types/connection';
|
||||
import availableAppsEnumType from '../types/available-apps-enum-type';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
import { GraphQLJSONObject } from 'graphql-type-json';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
type Params = {
|
||||
key: string;
|
||||
data: object;
|
||||
formattedData: IJSONObject;
|
||||
};
|
||||
const createConnectionResolver = async (
|
||||
params: Params,
|
||||
@@ -17,7 +18,7 @@ const createConnectionResolver = async (
|
||||
|
||||
const connection = await req.currentUser.$relatedQuery('connections').insert({
|
||||
key: params.key,
|
||||
data: params.data,
|
||||
formattedData: params.formattedData,
|
||||
});
|
||||
|
||||
return {
|
||||
@@ -30,7 +31,7 @@ const createConnection = {
|
||||
type: connectionType,
|
||||
args: {
|
||||
key: { type: GraphQLNonNull(availableAppsEnumType) },
|
||||
data: { type: GraphQLNonNull(GraphQLJSONObject) },
|
||||
formattedData: { type: GraphQLNonNull(GraphQLJSONObject) },
|
||||
},
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) =>
|
||||
createConnectionResolver(params, req),
|
||||
|
@@ -18,7 +18,7 @@ const resetConnectionResolver = async (
|
||||
.throwIfNotFound();
|
||||
|
||||
connection = await connection.$query().patchAndFetch({
|
||||
data: { screenName: connection.data.screenName },
|
||||
formattedData: { screenName: connection.formattedData.screenName },
|
||||
});
|
||||
|
||||
return connection;
|
||||
|
@@ -2,10 +2,11 @@ import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||
import { GraphQLJSONObject } from 'graphql-type-json';
|
||||
import connectionType from '../types/connection';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
type Params = {
|
||||
id: string;
|
||||
data: object;
|
||||
formattedData: IJSONObject;
|
||||
};
|
||||
|
||||
const updateConnectionResolver = async (
|
||||
@@ -20,9 +21,9 @@ const updateConnectionResolver = async (
|
||||
.throwIfNotFound();
|
||||
|
||||
connection = await connection.$query().patchAndFetch({
|
||||
data: {
|
||||
...connection.data,
|
||||
...params.data,
|
||||
formattedData: {
|
||||
...connection.formattedData,
|
||||
...params.formattedData,
|
||||
},
|
||||
});
|
||||
|
||||
|
@@ -21,13 +21,13 @@ const verifyConnectionResolver = async (
|
||||
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||
const appData = App.findOneByKey(connection.key);
|
||||
|
||||
const appInstance = new appClass(appData, connection.data);
|
||||
const appInstance = new appClass(appData, connection.formattedData);
|
||||
const verifiedCredentials =
|
||||
await appInstance.authenticationClient.verifyCredentials();
|
||||
|
||||
connection = await connection.$query().patchAndFetch({
|
||||
data: {
|
||||
...connection.data,
|
||||
formattedData: {
|
||||
...connection.formattedData,
|
||||
...verifiedCredentials,
|
||||
},
|
||||
verified: true,
|
||||
|
Reference in New Issue
Block a user