@@ -2464,14 +2464,28 @@ class Collective extends Model<
2464
2464
}
2465
2465
2466
2466
// 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
+ }
2475
2489
}
2476
2490
2477
2491
// Prepare events and projects to receive a new host
0 commit comments