@@ -12,7 +12,7 @@ const db = firestore();
1212 * Revokes all membership that are expired, but not yet revoked
1313 */
1414export const revokeMemberships = async ( ) : Promise < void > => {
15- logger . info ( `Beginning membership revoking for ${ new Date ( ) . getDate ( ) } ` ) ;
15+ logger . info ( `Beginning membership revoking for ${ new Date ( ) . toDateString ( ) } ` ) ;
1616
1717 // Only get the subscription cancelled by user, because the subscriptions
1818 // canceled by payment failure should already be revoked
@@ -21,8 +21,6 @@ export const revokeMemberships = async (): Promise<void> => {
2121 . where ( 'revoked' , '==' , false )
2222 . get ( ) as firestore . QuerySnapshot < ISubscriptionEntity > ;
2323
24- const promiseArr : Promise < any > [ ] = [ ] ;
25-
2624 for ( const subscriptionSnap of subscriptions . docs ) {
2725 const subscription = subscriptionSnap . data ( ) as ISubscriptionEntity ;
2826
@@ -36,20 +34,18 @@ export const revokeMemberships = async (): Promise<void> => {
3634 } else {
3735 // If the subscription is pass it's due date: revoke it, If is not leave it be
3836 if ( subscription . dueDate . toDate ( ) < new Date ( ) ) {
39- // eslint-disable-next-line no-loop-func
40- promiseArr . push ( ( async ( ) => {
41- // Add try/catch so that if one revoke fails
42- // the others won't be canceled because of it
43- try {
44- logger . info ( `Revoking membership for subscription with id ${ subscription . id } ` ) ;
45-
46- await revokeMembership ( subscription ) ;
47-
48- logger . info ( `Revoked membership ${ subscription . id } ` ) ;
49- } catch ( e ) {
50- logger . warn ( 'Error occurred while trying to revoke subscription' , e ) ;
51- }
52- } ) ( ) ) ;
37+ // Add try/catch so that if one revoke fails
38+ // the others won't be canceled because of it
39+ try {
40+ logger . info ( `Revoking membership for subscription with id ${ subscription . id } ` ) ;
41+
42+ // eslint-disable-next-line no-await-in-loop
43+ await revokeMembership ( subscription ) ;
44+
45+ logger . info ( `Revoked membership ${ subscription . id } ` ) ;
46+ } catch ( e ) {
47+ logger . warn ( 'Error occurred while trying to revoke subscription' , e ) ;
48+ }
5349 } else {
5450 logger . debug ( 'Skipping revoke for user canceled subscription' , {
5551 subscription
@@ -58,7 +54,5 @@ export const revokeMemberships = async (): Promise<void> => {
5854 }
5955 }
6056
61- await Promise . all ( promiseArr ) ;
62-
6357 logger . info ( `Memberships revoked successfully` ) ;
6458} ;
0 commit comments