refactor: rewrite test connection with RQ
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
import App from '../../models/app.js';
|
||||
import Connection from '../../models/connection.js';
|
||||
import globalVariable from '../../helpers/global-variable.js';
|
||||
|
||||
const testConnection = async (_parent, params, context) => {
|
||||
const conditions = context.currentUser.can('update', 'Connection');
|
||||
const userConnections = context.currentUser.$relatedQuery('connections');
|
||||
const allConnections = Connection.query();
|
||||
const connectionBaseQuery = conditions.isCreator
|
||||
? userConnections
|
||||
: allConnections;
|
||||
|
||||
let connection = await connectionBaseQuery
|
||||
.clone()
|
||||
.findOne({
|
||||
id: params.id,
|
||||
})
|
||||
.throwIfNotFound();
|
||||
|
||||
const app = await App.findOneByKey(connection.key, false);
|
||||
const $ = await globalVariable({ connection, app });
|
||||
|
||||
let isStillVerified;
|
||||
try {
|
||||
isStillVerified = !!(await app.auth.isStillVerified($));
|
||||
} catch {
|
||||
isStillVerified = false;
|
||||
}
|
||||
|
||||
connection = await connection.$query().patchAndFetch({
|
||||
formattedData: connection.formattedData,
|
||||
verified: isStillVerified,
|
||||
});
|
||||
|
||||
return connection;
|
||||
};
|
||||
|
||||
export default testConnection;
|
@@ -1,13 +1,11 @@
|
||||
import getAppAuthClient from './queries/get-app-auth-client.ee.js';
|
||||
import getConnectedApps from './queries/get-connected-apps.js';
|
||||
import getDynamicData from './queries/get-dynamic-data.js';
|
||||
import testConnection from './queries/test-connection.js';
|
||||
|
||||
const queryResolvers = {
|
||||
getAppAuthClient,
|
||||
getConnectedApps,
|
||||
getDynamicData,
|
||||
testConnection,
|
||||
};
|
||||
|
||||
export default queryResolvers;
|
||||
|
@@ -1,7 +1,6 @@
|
||||
type Query {
|
||||
getAppAuthClient(id: String!): AppAuthClient
|
||||
getConnectedApps(name: String): [App]
|
||||
testConnection(id: String!): Connection
|
||||
getDynamicData(
|
||||
stepId: String!
|
||||
key: String!
|
||||
|
Reference in New Issue
Block a user