feat: add shared connection capability

This commit is contained in:
Ali BARIN
2023-09-08 11:32:22 +00:00
parent aefff5c861
commit 099a8ea2cf
19 changed files with 315 additions and 103 deletions

View File

@@ -9,28 +9,55 @@ type Params = {
const getApp = async (_parent: unknown, params: Params, context: Context) => {
const conditions = context.currentUser.can('read', 'Connection');
const userConnections = context.currentUser.$relatedQuery('connections');
const allConnections = Connection.query();
const connectionBaseQuery = conditions.isCreator ? userConnections : allConnections;
const app = await App.findOneByKey(params.key);
if (context.currentUser) {
const connections = await connectionBaseQuery
.clone()
.select('connections.*')
const userConnections = context.currentUser.relatedConnectionsQuery();
const allConnections = Connection.query();
const connectionBaseQuery = conditions.isCreator ? userConnections : allConnections;
const connections = await Connection.query()
.with('connections', connectionBaseQuery)
.with(
'connections_with_flow_count',
Connection.query()
.clearSelect()
.select('connections.id')
.leftJoinRelated('steps')
.leftJoin('flows', function () {
this
.on(
'flows.id',
'=',
'steps.flow_id',
)
if (conditions.isCreator) {
this.andOnVal(
'flows.user_id',
'=',
context.currentUser.id
)
}
})
.where({
'connections.key': params.key,
'connections.draft': false,
})
.countDistinct('steps.flow_id as flowCount')
.groupBy('connections.id')
)
.select(
'connections.*',
'connections_with_flow_count.flowCount as flowCount'
)
.from('connections')
.withGraphFetched({
appConfig: true,
appAuthClient: true
})
.fullOuterJoinRelated('steps')
.where({
'connections.key': params.key,
'connections.draft': false,
})
.countDistinct('steps.flow_id as flowCount')
.groupBy('connections.id')
.orderBy('created_at', 'desc');
.joinRaw('join connections_with_flow_count on connections.id = connections_with_flow_count.id')
.orderBy('connections.created_at', 'desc');
return {
...app,