All files / src/repositories company-persona.repository.ts

100% Statements 20/20
100% Branches 0/0
100% Functions 1/1
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 811x 1x           1x 1x 1x                     1x                                             68x   68x   68x   68x   68x   68x     68x       68x           68x       68x     68x       68x      
import {Getter, inject} from '@loopback/core';
import {
  BelongsToAccessor,
  HasManyRepositoryFactory,
  HasOneRepositoryFactory,
  repository,
} from '@loopback/repository';
import {BaseCrudRepository, CompanyRepository, UserRepository} from '.';
import {LogChainDataSource} from '../datasources';
import {
  Company,
  CompanyLocation,
  CompanyPersona,
  CompanyPersonaRelations,
  Persona,
  User,
} from '../models';
import {CompanyLocationRepository} from './company-location.repository';
import {PersonaRepository} from './persona.repository';
 
export class CompanyPersonaRepository extends BaseCrudRepository<
  CompanyPersona,
  typeof CompanyPersona.prototype.id,
  CompanyPersonaRelations
> {
  public readonly creator: BelongsToAccessor<User, typeof User.prototype.id>;
  public readonly modifier: BelongsToAccessor<User, typeof User.prototype.id>;
  public readonly locations: HasManyRepositoryFactory<
    CompanyLocation,
    typeof CompanyPersona.prototype.id
  >;
  public readonly persona: HasOneRepositoryFactory<
    Persona,
    typeof Persona.prototype.id
  >;
 
  public readonly company: HasOneRepositoryFactory<
    Company,
    typeof Company.prototype.id
  >;
  constructor(
    @inject('datasources.logchain') dataSource: LogChainDataSource,
    @repository.getter('CompanyLocationRepository')
    protected companyLocationRepositoryGetter: Getter<CompanyLocationRepository>,
    @repository.getter('UserRepository')
    protected userRepoGetter: Getter<UserRepository>,
    @repository.getter('PersonaRepository')
    protected personaRepoGetter: Getter<PersonaRepository>,
    @repository.getter('CompanyRepository')
    protected companyRepoGetter: Getter<CompanyRepository>,
  ) {
    super(CompanyPersona, dataSource);
    // register creator relation
    this.creator = this.createBelongsToAccessor('creator', userRepoGetter);
 
    // register locations relation
    this.locations = this.createHasManyRepositoryFactoryFor(
      'locations',
      companyLocationRepositoryGetter,
    );
    this.registerInclusionResolver(
      'locations',
      this.locations.inclusionResolver,
    );
 
    // register persona relation
    this.persona = this.createHasOneRepositoryFactoryFor(
      'persona',
      personaRepoGetter,
    );
    this.registerInclusionResolver('persona', this.persona.inclusionResolver);
 
    // register company relation
    this.company = this.createHasOneRepositoryFactoryFor(
      'company',
      companyRepoGetter,
    );
    this.registerInclusionResolver('company', this.company.inclusionResolver);
  }
}