-
-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unsubscribe original territory owner on transfer or unarchive #1791
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,14 +240,23 @@ export default { | |
if (!user) { | ||
throw new GqlInputError('user not found') | ||
} | ||
if (user.id === me.id) { | ||
|
||
const oldUserId = me.id | ||
const newUserId = user.id | ||
|
||
if (newUserId === oldUserId) { | ||
throw new GqlInputError('cannot transfer territory to yourself') | ||
} | ||
|
||
const [, updatedSub] = await models.$transaction([ | ||
models.territoryTransfer.create({ data: { subName, oldUserId: me.id, newUserId: user.id } }), | ||
models.sub.update({ where: { name: subName }, data: { userId: user.id, billingAutoRenew: false } }) | ||
]) | ||
const updatedSub = await models.$transaction(async tx => { | ||
await tx.territoryTransfer.create({ data: { subName, oldUserId, newUserId } }) | ||
const updatedSub = await tx.sub.update({ where: { name: subName }, data: { userId: newUserId, billingAutoRenew: false } }) | ||
|
||
// unsubscribe the old user | ||
const oldSubscription = await tx.subSubscription.findUnique({ where: { userId_subName: { userId: oldUserId, subName } } }) | ||
if (oldSubscription) await tx.subSubscription.delete({ where: { userId_subName: { subName, userId: oldUserId } } }) | ||
return updatedSub | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it also subscribe the new user if they aren't already? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah, I'd say let's not automatically subscribe them for the reason you mentioned |
||
}) | ||
|
||
notifyTerritoryTransfer({ models, sub, to: user }) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you prefer this or deleteMany?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
delete
should be fine. But do you need to check first if it exists?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, delete will error if the record does not exist (eg. if the user unsubscribed manually before transferring the territory) the workaround is to use deleteMany that will not error.
But in this case, since it is already inside a transaction, maybe this is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use
deleteMany
then