@sourceloop/ctrl-plane-tenant-management-service
Version:
Tenant Management microservice for SaaS control plane
64 lines (57 loc) • 1.83 kB
text/typescript
import {Getter, inject} from '@loopback/core';
import {
DefaultUserModifyCrudRepository,
IAuthUserWithPermissions,
} from '@sourceloop/core';
import {
BelongsToAccessor,
Entity,
HasOneRepositoryFactory,
juggler,
repository,
} from '@loopback/repository';
import {SYSTEM_USER} from '../keys';
import {Address, Lead, LeadRelations, Tenant} from '../models';
import {TenantRepository} from './tenant.repository';
import {AddressRepository} from './address.repository';
import {TenantManagementDbSourceName} from '../types';
export class LeadRepository<
T extends Lead = Lead,
> extends DefaultUserModifyCrudRepository<
T,
typeof Lead.prototype.id,
LeadRelations
> {
public readonly tenant: HasOneRepositoryFactory<
Tenant,
typeof Tenant.prototype.id
>;
public readonly address: BelongsToAccessor<
Address,
typeof Tenant.prototype.id
>;
constructor(
(`datasources.${TenantManagementDbSourceName}`)
dataSource: juggler.DataSource,
.getter(SYSTEM_USER)
public readonly getCurrentUser: Getter<IAuthUserWithPermissions>,
.getter('TenantRepository')
protected tenantRepositoryGetter: Getter<TenantRepository>,
.getter('AddressRepository')
protected addressRepositoryGetter: Getter<AddressRepository>,
('models.Lead')
private readonly lead: typeof Entity & {prototype: T},
) {
super(lead, dataSource, getCurrentUser);
this.tenant = this.createHasOneRepositoryFactoryFor(
'tenant',
tenantRepositoryGetter,
);
this.registerInclusionResolver('tenant', this.tenant.inclusionResolver);
this.address = this.createBelongsToAccessorFor(
'address',
addressRepositoryGetter,
);
this.registerInclusionResolver('address', this.address.inclusionResolver);
}
}