import { Inject , Injectable } from '@nestjs/common' ; import { InjectRepository } from '@nestjs/typeorm' ; import { RepositoryEntity } from '@pimp-my-pr/server/repository/core/domain' ; import { RepositoryRepository } from '@pimp-my-pr/server/repository/core/domain-services' ; import { Platform } from '@pimp-my-pr/shared/domain' ; import { Repository } from 'typeorm' ; import { RepositorySchema } from '../typeorm/schema/repository.schema' ; import { RemoteRepositoryRepository , remoteRepositoryRepositoryFactoryToken } from './remote-repository.repository' ; @ Injectable ( ) export class RepositoryRepositoryAdapter extends RepositoryRepository { constructor ( @ InjectRepository ( RepositorySchema as any ) private typeOrmRepository , @ Inject ( remoteRepositoryRepositoryFactoryToken ) private repositoryFactory ) { super ( ) ; } async findAll ( ) { return this . typeOrmRepository . find ( ) ; } findByUserId ( userId ) { return this . typeOrmRepository . find ( { userId } ) ; } getById ( id ) { return this . typeOrmRepository . findOneOrFail ( id ) ; } getByData ( userId , name , owner ) { return this . typeOrmRepository . findOne ( { userId , name } ) ; } loadRepositoryByName ( fullName , token , platform ) { const repository = this . repositoryFactory ( platform ) ; return repository . getSingleRepositoryByName ( fullName , token ) ; } async save ( repository ) { await this . typeOrmRepository . save ( repository ) ; } async delete ( repository ) { await this . typeOrmRepository . remove ( repository ) ; } }