feat: add app connections w/ testing and deleting functions
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user