@@ -8,6 +8,8 @@ import {durationOf} from "../../http/utils";
88import DocumentData = firestore . DocumentData ;
99import QuerySnapshot = firestore . QuerySnapshot ;
1010import { User } from "../../../../../../shared/user.firestore" ;
11+ import { UserTokensWallet } from "../../../../../../shared/user-tokens-wallet.localstorage" ;
12+ import DocumentSnapshot = firestore . DocumentSnapshot ;
1113
1214
1315async function getRawUsersMatching ( collectionFilter : ( collection : CollectionReference ) => Query ) {
@@ -113,23 +115,25 @@ export async function windowedProcessUsers(
113115}
114116
115117async function deleteUserRefIncludingChildren ( userRef : DocumentReference < DocumentData > , force = false ) {
116- const [ preferencesDoc , tokensWalletDoc ] = await Promise . all ( [
117- db . doc ( `/users/${ userRef . id } /preferences/self` ) . get ( ) ,
118- db . doc ( `/users/${ userRef . id } /tokens-wallet/self` ) . get ( ) ,
119- ] )
120-
121- // let's not delete
122- const collectionsPreventingDelete = ( [ ] as string [ ] )
123- . concat ( preferencesDoc . exists ? [ "preferences" ] :[ ] )
124- . concat ( tokensWalletDoc . exists ? [ "tokens-wallet" ] :[ ] )
125- if ( collectionsPreventingDelete . length && ! force ) {
126- console . info ( `Not deleting user ${ userRef . id } because he has ${ collectionsPreventingDelete . join ( "/" ) } non-empty collection` )
118+ const tokensWalletDoc = await db . doc ( `${ userRef . path } /tokens-wallet/self` ) . get ( ) as DocumentSnapshot < UserTokensWallet >
119+ const walletSecrets = tokensWalletDoc . data ( ) ?. secretTokens ;
120+
121+ if ( ! force && tokensWalletDoc . exists && walletSecrets && (
122+ ( walletSecrets . eventOrganizerTokens && walletSecrets . eventOrganizerTokens . length )
123+ || ( walletSecrets . privateSpaceTokens && walletSecrets . privateSpaceTokens . length )
124+ || ( walletSecrets . talkFeedbacksViewerTokens && walletSecrets . talkFeedbacksViewerTokens . length )
125+ ) ) {
126+ console . info ( `Not deleting user ${ userRef . id } because he has tokens-wallet non-empty collection` )
127127 return ;
128128 }
129129
130+ const preferencesDoc = await db . doc ( `${ userRef . path } /preferences/self` ) . get ( )
131+
130132 await Promise . all ( [
131133 deleteUserSpaces ( userRef ) ,
132134 deleteUserEventsFromNode ( userRef ) ,
135+ ...( preferencesDoc . exists ? [ preferencesDoc . ref . delete ( ) ] :[ ] ) ,
136+ ...( tokensWalletDoc . exists ? [ tokensWalletDoc . ref . delete ( ) ] :[ ] ) ,
133137 ] )
134138
135139 console . info ( `Deleting user entry ${ userRef . path } ` )
0 commit comments