Skip to content

Commit 6c5e1ce

Browse files
committed
chore: check for existing flow connection
1 parent 22b4cef commit 6c5e1ce

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

packages/backend/src/models/flow-connections.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,29 @@ class FlowConnections extends Base {
109109
if (hasCollaborators) {
110110
// NOTE: somehow .onConflict().ignore() does not return an empty array
111111
// on conflict, but actually returns the row its trying to insert
112-
const existing = await this.query(trx).findOne({
113-
flow_id: flowId,
114-
connection_id: connectionId,
115-
})
112+
113+
// check if the connection existed before and was deleted
114+
const existing = await this.query(trx)
115+
.findOne({
116+
flow_id: flowId,
117+
connection_id: connectionId,
118+
})
119+
.withSoftDeleted()
116120

117121
if (existing) {
118-
return null
122+
// if it existed before and was deleted, restore it
123+
return await this.query(trx)
124+
.where({
125+
flow_id: flowId,
126+
connection_id: connectionId,
127+
})
128+
.patch({
129+
deletedAt: null,
130+
})
131+
.withSoftDeleted()
119132
}
120133

134+
// if it did not exist before, add it
121135
return await this.query(trx)
122136
.insert({
123137
flowId,

0 commit comments

Comments
 (0)