Skip to content

Commit 4620160

Browse files
authored
Fix unique constraint hit during territory unarchive (#2245)
1 parent a5de2da commit 4620160

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

api/paidAction/territoryUnarchive.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,16 @@ export async function perform ({ name, invoiceId, ...data }, { me, cost, tx }) {
7878
}
7979
})
8080

81-
await tx.userSubTrust.createMany({
82-
data: initialTrust({ name: updatedSub.name, userId: updatedSub.userId })
83-
})
81+
const trust = initialTrust({ name: updatedSub.name, userId: updatedSub.userId })
82+
for (const t of trust) {
83+
await tx.userSubTrust.upsert({
84+
where: {
85+
userId_subName: { userId: t.userId, subName: t.subName }
86+
},
87+
update: t,
88+
create: t
89+
})
90+
}
8491

8592
return updatedSub
8693
}

0 commit comments

Comments
 (0)