feat: add shared connection capability
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user