Skip to content

Commit

Permalink
enhancement(Collective): expire host application when withdrawing
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed May 3, 2024
1 parent c06e65c commit d086632
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion server/graphql/v2/mutation/HostApplicationMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ const rejectApplication = async (host, collective, req, reason: string) => {
const { remoteUser } = req;

// Reset host for collective & its children
await models.HostApplication.updatePendingApplications(host, collective, HostApplicationStatus.REJECTED);
await collective.changeHost(null, remoteUser);

// Notify collective admins
Expand All @@ -395,7 +396,6 @@ const rejectApplication = async (host, collective, req, reason: string) => {

// Purge cache and change the status of the application
purgeCacheForCollective(collective.slug);
await models.HostApplication.updatePendingApplications(host, collective, HostApplicationStatus.REJECTED);
return collective;
};

Expand Down
30 changes: 22 additions & 8 deletions server/models/Collective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2464,14 +2464,28 @@ class Collective extends Model<
}

// Deactivate/remote everything related to previous host
if (this.HostCollectiveId && this.approvedAt) {
// Pause or cancel all orders that cannot be transferred
const newOrderStatus = pauseContributions ? OrderStatuses.PAUSED : OrderStatuses.CANCELLED;
await Order.stopActiveSubscriptions(this.id, newOrderStatus, { messageForContributors, messageSource });

// Delete all virtual cards
const virtualCards = await VirtualCard.findAll({ where: { CollectiveId: this.id } });
await Promise.all(virtualCards.map(virtualCard => virtualCard.delete()));
if (this.HostCollectiveId) {
if (this.approvedAt) {
// Pause or cancel all orders that cannot be transferred
const newOrderStatus = pauseContributions ? OrderStatuses.PAUSED : OrderStatuses.CANCELLED;
await Order.stopActiveSubscriptions(this.id, newOrderStatus, { messageForContributors, messageSource });

// Delete all virtual cards
const virtualCards = await VirtualCard.findAll({ where: { CollectiveId: this.id } });
await Promise.all(virtualCards.map(virtualCard => virtualCard.delete()));
} else {
// Expire all pending host applications
await HostApplication.update(
{ status: HostApplicationStatus.EXPIRED },
{
where: {
HostCollectiveId: this.HostCollectiveId,
CollectiveId: this.id,
status: HostApplicationStatus.PENDING,
},
},
);
}
}

// Prepare events and projects to receive a new host
Expand Down

0 comments on commit d086632

Please sign in to comment.