feat: add app connections w/ testing and deleting functions
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { GraphQLList, GraphQLString, GraphQLNonNull } from 'graphql';
|
||||
import Connection from '../../models/connection';
|
||||
import App from '../../models/app';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
import connectionType from '../types/connection';
|
||||
|
||||
@@ -8,10 +9,14 @@ type Params = {
|
||||
}
|
||||
|
||||
const getAppConnectionsResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
const app = await App.findOneByKey(params.key);
|
||||
const connections = await Connection.query()
|
||||
.where({ user_id: req.currentUser.id, verified: true, key: params.key })
|
||||
.where({ user_id: req.currentUser.id, key: params.key })
|
||||
|
||||
return connections;
|
||||
return connections.map((connection: any) => ({
|
||||
...connection,
|
||||
app,
|
||||
}));
|
||||
}
|
||||
|
||||
const getAppConnections = {
|
||||
|
@@ -1,17 +1,32 @@
|
||||
import { GraphQLString, GraphQLNonNull } from 'graphql';
|
||||
import App from '../../models/app';
|
||||
import appType from '../types/app';
|
||||
import RequestWithCurrentUser from '../../types/express/request-with-current-user';
|
||||
import Connection from '../../models/connection';
|
||||
import connectionType from '../types/connection';
|
||||
|
||||
type Params = {
|
||||
key: string
|
||||
}
|
||||
|
||||
const getAppResolver = (params: Params) => {
|
||||
const getAppResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||
if(!params.key) {
|
||||
throw new Error('No key provided.')
|
||||
}
|
||||
|
||||
return App.findOneByKey(params.key)
|
||||
const app = await App.findOneByKey(params.key);
|
||||
|
||||
if (req.currentUser?.id) {
|
||||
const connections = await Connection.query()
|
||||
.where({ user_id: req.currentUser.id, key: params.key });
|
||||
|
||||
return {
|
||||
...app,
|
||||
connections,
|
||||
};
|
||||
}
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
const getApp = {
|
||||
@@ -19,9 +34,7 @@ const getApp = {
|
||||
args: {
|
||||
key: { type: GraphQLNonNull(GraphQLString) },
|
||||
},
|
||||
resolve: (_: any, params: Params) => getAppResolver(params)
|
||||
resolve: (_: any, params: Params, req: RequestWithCurrentUser) => getAppResolver(params, req)
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default getApp;
|
||||
|
@@ -15,7 +15,7 @@ const testConnectionResolver = async (params: Params, req: RequestWithCurrentUse
|
||||
|
||||
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||
|
||||
const appInstance = new appClass(connection.data)
|
||||
const appInstance = new appClass(connection.data);
|
||||
const isStillVerified = await appInstance.isStillVerified();
|
||||
|
||||
connection = await connection.$query().patchAndFetch({
|
||||
|
Reference in New Issue
Block a user