refactor: rewrite test connection with RQ

This commit is contained in:
Rıdvan Akca
2024-04-10 12:58:05 +02:00
parent 17fb935ea0
commit 5c9d3ed134
7 changed files with 43 additions and 82 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -1,7 +1,6 @@
type Query {
getAppAuthClient(id: String!): AppAuthClient
getConnectedApps(name: String): [App]
testConnection(id: String!): Connection
getDynamicData(
stepId: String!
key: String!