Skip to content

Commit 17d3d37

Browse files
committed
enhancement(Collective): expire host application when withdrawing
1 parent c06e65c commit 17d3d37

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

server/models/Collective.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -2464,14 +2464,28 @@ class Collective extends Model<
24642464
}
24652465

24662466
// Deactivate/remote everything related to previous host
2467-
if (this.HostCollectiveId && this.approvedAt) {
2468-
// Pause or cancel all orders that cannot be transferred
2469-
const newOrderStatus = pauseContributions ? OrderStatuses.PAUSED : OrderStatuses.CANCELLED;
2470-
await Order.stopActiveSubscriptions(this.id, newOrderStatus, { messageForContributors, messageSource });
2471-
2472-
// Delete all virtual cards
2473-
const virtualCards = await VirtualCard.findAll({ where: { CollectiveId: this.id } });
2474-
await Promise.all(virtualCards.map(virtualCard => virtualCard.delete()));
2467+
if (this.HostCollectiveId) {
2468+
if (this.approvedAt) {
2469+
// Pause or cancel all orders that cannot be transferred
2470+
const newOrderStatus = pauseContributions ? OrderStatuses.PAUSED : OrderStatuses.CANCELLED;
2471+
await Order.stopActiveSubscriptions(this.id, newOrderStatus, { messageForContributors, messageSource });
2472+
2473+
// Delete all virtual cards
2474+
const virtualCards = await VirtualCard.findAll({ where: { CollectiveId: this.id } });
2475+
await Promise.all(virtualCards.map(virtualCard => virtualCard.delete()));
2476+
} else {
2477+
// Expire all pending host applications
2478+
await HostApplication.update(
2479+
{ status: HostApplicationStatus.EXPIRED },
2480+
{
2481+
where: {
2482+
HostCollectiveId: this.HostCollectiveId,
2483+
CollectiveId: this.id,
2484+
status: HostApplicationStatus.PENDING,
2485+
},
2486+
},
2487+
);
2488+
}
24752489
}
24762490

24772491
// Prepare events and projects to receive a new host

0 commit comments

Comments
 (0)