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 Apr 30, 2024
1 parent c06e65c commit 17d3d37
Showing 1 changed file with 22 additions and 8 deletions.
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 17d3d37

Please sign in to comment.