-
Notifications
You must be signed in to change notification settings - Fork 70
/
tenant-config.repository.ts
45 lines (43 loc) · 1.47 KB
/
tenant-config.repository.ts
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
// Copyright (c) 2023 Sourcefuse Technologies
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
import {Getter, inject} from '@loopback/core';
import {BelongsToAccessor, juggler, repository} from '@loopback/repository';
import {
DefaultUserModifyCrudRepository,
IAuthUserWithPermissions,
tenantGuard,
} from '@sourceloop/core';
import {AuthenticationBindings} from 'loopback4-authentication';
import {UserTenantDataSourceName} from '../keys';
import {Tenant, TenantConfig, TenantConfigRelations} from '../models';
import {TenantRepository} from './tenant.repository';
@tenantGuard()
export class TenantConfigRepository extends DefaultUserModifyCrudRepository<
TenantConfig,
typeof TenantConfig.prototype.id,
TenantConfigRelations
> {
public readonly tenant: BelongsToAccessor<
Tenant,
typeof TenantConfig.prototype.id
>;
constructor(
@inject(`datasources.${UserTenantDataSourceName}`)
dataSource: juggler.DataSource,
@repository.getter('TenantRepository')
protected tenantRepositoryGetter: Getter<TenantRepository>,
@inject.getter(AuthenticationBindings.CURRENT_USER)
protected readonly getCurrentUser: Getter<
IAuthUserWithPermissions | undefined
>,
) {
super(TenantConfig, dataSource, getCurrentUser);
this.tenant = this.createBelongsToAccessorFor(
'tenant',
tenantRepositoryGetter,
);
this.registerInclusionResolver('tenant', this.tenant.inclusionResolver);
}
}