feat: add app connections w/ testing and deleting functions

This commit is contained in:
Ali BARIN
2021-10-18 23:58:40 +02:00
parent 672cc4c60c
commit 2293c939e7
27 changed files with 349 additions and 34 deletions

View File

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