diff --git a/api/paidAction/territoryUnarchive.js b/api/paidAction/territoryUnarchive.js index bb547be8..95c63eb7 100644 --- a/api/paidAction/territoryUnarchive.js +++ b/api/paidAction/territoryUnarchive.js @@ -36,6 +36,7 @@ export async function perform ({ name, invoiceId, ...data }, { me, cost, tx }) { if (sub.userId !== me.id) { await tx.territoryTransfer.create({ data: { subName: name, oldUserId: sub.userId, newUserId: me.id } }) + await tx.subSubscription.delete({ where: { userId_subName: { userId: sub.userId, subName: name } } }) } await tx.subAct.create({ @@ -47,6 +48,23 @@ export async function perform ({ name, invoiceId, ...data }, { me, cost, tx }) { } }) + await tx.subSubscription.upsert({ + where: { + userId_subName: { + userId: me.id, + subName: name + } + }, + update: { + userId: me.id, + subName: name + }, + create: { + userId: me.id, + subName: name + } + }) + return await tx.sub.update({ data, // optimistic concurrency control