import { IUser } from '@/boundary/userApplicationService/InOutType' ; import { User } from '@/models/user' ; import { IUserObservableRepository } from '@/query/observableRepository/user/IUserObservableRepository' ; import { injectable } from 'inversify' ; import { docData } from 'rxfire/firestore' ; import { Observable } from 'rxjs' ; import { filter , map } from 'rxjs/operators' ; function userMapper ( userId , user ) { return { ... user , id : userId , birthday : user . birthday . toDate ( ) , hireDate : user . hireDate . toDate ( ) , createdAt : user . createdAt . toDate ( ) , updatedAt : user . updatedAt && user . updatedAt . toDate ( ) || null , } ; } function isDoc ( data ) { return data && Object . keys ( data ) . length > 0 ; } @ injectable ( ) export class UserObservableRepository implements IUserObservableRepository { public getUser ( id ) { const docRef = User . getReference ( ) . doc ( id ) ; return docData ( docRef ) . pipe ( filter ( isDoc ) ) . pipe ( map ( ( data ) => userMapper ( id , data ) ) ) ; } }