import { firestore as Firestore } from 'firebase' ; import { firestore , functions } from 'src/firebase' ; import { User , UserFirestoreConverter } from 'src/models/users' ; import { PrivilegedUserInformation , PrivilegedUserInformationFirestoreConverter , } from 'src/models/users/privilegedInformation' ; import { IgetUserProfile } from './types' ; export const getUserProfile = ( payload ) : Promise < [ Firestore . DocumentSnapshot , Firestore . DocumentSnapshot ] > => Promise . all ( [ firestore . collection ( 'users' ) . doc ( payload . uid ) . withConverter ( UserFirestoreConverter ) . get ( ) , firestore . collection ( 'users' ) . doc ( payload . uid ) . collection ( 'privilegedInformation' ) . doc ( payload . uid ) . withConverter ( PrivilegedUserInformationFirestoreConverter ) . get ( ) , ] ) ; export const observePrivileged = ( nextValue , payload ) : firebase . Unsubscribe => firestore . collection ( 'users' ) . doc ( payload . uid ) . collection ( 'privilegedInformation' ) . doc ( payload . uid ) . withConverter ( PrivilegedUserInformationFirestoreConverter ) . onSnapshot ( snap => nextValue ( snap ) ) ; export const observeProfile = ( nextValue , payload ) : firebase . Unsubscribe => firestore . collection ( 'users' ) . doc ( payload . uid ) . withConverter ( UserFirestoreConverter ) . onSnapshot ( snap => nextValue ( snap ) ) ; export const setUserProfile = async ( { uid , userPayload , privilegedPayload , } ) => { await firestore . collection ( 'users' ) . doc ( uid ) . withConverter ( UserFirestoreConverter ) . set ( userPayload ) ; return firestore . collection ( 'users' ) . doc ( uid ) . collection ( 'privilegedInformation' ) . doc ( uid ) . withConverter ( PrivilegedUserInformationFirestoreConverter ) . set ( privilegedPayload ) ; } ; export const updateUserProfileData = async ( { uid , userPayload , } ) => firestore . collection ( 'users' ) . doc ( uid ) . withConverter ( UserFirestoreConverter ) . set ( userPayload ) ; export const updateUserPrivilegedInformationData = async ( { uid , dataPayload , } ) => firestore . collection ( 'users' ) . doc ( uid ) . collection ( 'privilegedInformation' ) . doc ( uid ) . withConverter ( PrivilegedUserInformationFirestoreConverter ) . set ( dataPayload ) ; export const deleteUserData = async ( ) => functions . httpsCallable ( 'https-api-users-deleteUserData' ) ( ) ;