Skip to content

Commit 64ace68

Browse files
committed
remove softDeleted, wrap in trx
1 parent aefd3ca commit 64ace68

File tree

3 files changed

+18
-31
lines changed

3 files changed

+18
-31
lines changed

packages/backend/src/graphql/__tests__/mutations/update-step.itest.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -588,12 +588,10 @@ describe('updateStep mutation', () => {
588588
// Mock FlowConnections query for getConnection validation
589589
// Since role is 'editor', getConnection will query FlowConnections table
590590
vi.spyOn(FlowConnections, 'query').mockReturnValue({
591-
withSoftDeleted: vi.fn().mockReturnValue({
592-
findOne: vi.fn().mockReturnValue({
593-
withGraphFetched: vi.fn().mockReturnValue({
594-
throwIfNotFound: vi.fn().mockResolvedValue({
595-
connection: { id: mockConnectionId, key: 'slack' },
596-
}),
591+
findOne: vi.fn().mockReturnValue({
592+
withGraphFetched: vi.fn().mockReturnValue({
593+
throwIfNotFound: vi.fn().mockResolvedValue({
594+
connection: { id: mockConnectionId, key: 'slack' },
597595
}),
598596
}),
599597
}),

packages/backend/src/graphql/mutations/delete-connection.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@ const deleteConnection: MutationResolvers['deleteConnection'] = async (
77
params,
88
context,
99
) => {
10-
await context.currentUser
11-
.$relatedQuery('connections')
12-
.delete()
13-
.findOne({
14-
id: params.input.id,
15-
})
16-
.throwIfNotFound()
10+
return await FlowConnections.transaction(async (trx) => {
11+
await context.currentUser
12+
.$relatedQuery('connections', trx)
13+
.delete()
14+
.findOne({
15+
id: params.input.id,
16+
})
17+
.throwIfNotFound()
1718

18-
// also delete the connection from the flow_connections table for flows with collaborators
19-
await FlowConnections.query()
20-
.delete()
21-
.where({ connection_id: params.input.id })
19+
// also delete the connection from the flow_connections table for flows with collaborators
20+
await FlowConnections.query(trx)
21+
.delete()
22+
.where({ connection_id: params.input.id })
2223

23-
return true
24+
return true
25+
})
2426
}
2527

2628
export default deleteConnection

packages/backend/src/services/connection.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ export const getConnection = async (params: GetConnectionParams) => {
2727
// 2. the user is the owner of a pipe that has been transferred to them
2828
// it should include connections from the flow_connections table as well
2929
//
30-
// NOTE: if the connection was deleted, we don't want to throw an error,
31-
// we just want to return null so we can show 'Not connected'
32-
//
3330
// TODO (kevinkim-ogp): phase 2 will allow editors to add their own connections, so owner's connections
3431
// will need to include connections from the flow_connections table
3532

@@ -40,33 +37,23 @@ export const getConnection = async (params: GetConnectionParams) => {
4037
this.where('connections.user_id', context.currentUser.id).orWhereExists(
4138
// or accessible via flow_connections table
4239
FlowConnections.query(trx)
43-
.withSoftDeleted()
4440
.whereColumn('flow_connections.connection_id', 'connections.id')
4541
.where('flow_connections.flow_id', flowId),
4642
)
4743
})
4844
.throwIfNotFound({ message: 'Connection not found' })
4945

50-
if (connection?.deletedAt) {
51-
return null
52-
}
53-
5446
return connection
5547
}
5648

5749
// NOTE: editor and viewer can only access shared connections from the flow_connections table
5850
const flowConnection = await FlowConnections.query(trx)
59-
.withSoftDeleted()
6051
.findOne({
6152
connection_id: connectionId,
6253
flow_id: flowId,
6354
})
6455
.withGraphFetched('connection')
6556
.throwIfNotFound({ message: 'Connection not found' })
6657

67-
if (flowConnection?.deletedAt) {
68-
return null
69-
}
70-
7158
return flowConnection?.connection
7259
}

0 commit comments

Comments
 (0)