From 47faef872d803523b4657bf2d72c2ee5642150f3 Mon Sep 17 00:00:00 2001 From: soxa <6390896+Soxasora@users.noreply.github.com> Date: Thu, 23 Jan 2025 02:11:19 +0100 Subject: [PATCH] Subscribe unarchiver to unarchived territory (#1839) * enhance: subscribe unarchiver to unarchived territory * use upsert and fix #1517 --------- Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com> Co-authored-by: k00b --- api/paidAction/territoryUnarchive.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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