import { Inject , Injectable } from '@nestjs/common' ; import { InjectRepository } from '@nestjs/typeorm' ; import { User } from '@pimp-my-pr/server/user/core/domain' ; import { UserRepository } from '@pimp-my-pr/server/user/core/domain-services' ; import { Platform } from '@pimp-my-pr/shared/domain' ; import { Repository } from 'typeorm' ; import { UserSchema } from '../schema/user.schema' ; import { remoteUserRepositoryFactoryToken } from './remote-user-repository.factory' ; import { RemoteUserRepository } from './remote-user.repository' ; @ Injectable ( ) export class UserRepositoryAdapter extends UserRepository { constructor ( @ Inject ( remoteUserRepositoryFactoryToken ) private remoteUserRepository , @ InjectRepository ( UserSchema as any ) private typeOrmRepository ) { super ( ) ; } findById ( id ) { return this . typeOrmRepository . findOne ( id ) ; } getById ( userId ) { return this . typeOrmRepository . findOneOrFail ( userId ) ; } loadCurrentUser ( token , platform ) { const remoteUserRepository = this . remoteUserRepository ( platform ) ; return remoteUserRepository . getCurrentUser ( token ) ; } save ( user ) { return this . typeOrmRepository . save ( user ) ; } }