Skip to content

Commit e692152

Browse files
committed
use upsert and fix stackernews#1517
1 parent a33c0d6 commit e692152

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

api/paidAction/territoryUnarchive.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export async function perform ({ name, invoiceId, ...data }, { me, cost, tx }) {
3636

3737
if (sub.userId !== me.id) {
3838
await tx.territoryTransfer.create({ data: { subName: name, oldUserId: sub.userId, newUserId: me.id } })
39+
await tx.subSubscription.delete({ where: { userId_subName: { userId: sub.userId, subName: name } } })
3940
}
4041

4142
await tx.subAct.create({
@@ -47,8 +48,18 @@ export async function perform ({ name, invoiceId, ...data }, { me, cost, tx }) {
4748
}
4849
})
4950

50-
await tx.subSubscription.create({
51-
data: {
51+
await tx.subSubscription.upsert({
52+
where: {
53+
userId_subName: {
54+
userId: me.id,
55+
subName: name
56+
}
57+
},
58+
update: {
59+
userId: me.id,
60+
subName: name
61+
},
62+
create: {
5263
userId: me.id,
5364
subName: name
5465
}

0 commit comments

Comments
 (0)