-
Notifications
You must be signed in to change notification settings - Fork 70
/
tenant.repository.ts
113 lines (107 loc) · 3.35 KB
/
tenant.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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// 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 {
HasManyRepositoryFactory,
juggler,
repository,
} from '@loopback/repository';
import {
DefaultUserModifyCrudRepository,
IAuthUserWithPermissions,
} from '@sourceloop/core';
import {AuthenticationBindings} from 'loopback4-authentication';
import {UserTenantDataSourceName} from '../keys';
import {
Group,
Role,
Tenant,
TenantConfig,
TenantRelations,
User,
UserTenant,
} from '../models';
import {GroupRepository} from './group.repository';
import {RoleRepository} from './role.repository';
import {TenantConfigRepository} from './tenant-config.repository';
import {UserTenantRepository} from './user-tenant.repository';
import {UserRepository} from './user.repository';
export class TenantRepository extends DefaultUserModifyCrudRepository<
Tenant,
typeof Tenant.prototype.id,
TenantRelations
> {
public readonly tenantConfigs: HasManyRepositoryFactory<
TenantConfig,
typeof Tenant.prototype.id
>;
public readonly userTenants: HasManyRepositoryFactory<
UserTenant,
typeof Tenant.prototype.id
>;
public readonly users: HasManyRepositoryFactory<
User,
typeof Tenant.prototype.id
>;
public readonly roles: HasManyRepositoryFactory<
Role,
typeof Tenant.prototype.id
>;
public readonly groups: HasManyRepositoryFactory<
Group,
typeof Tenant.prototype.id
>;
constructor(
@inject(`datasources.${UserTenantDataSourceName}`)
dataSource: juggler.DataSource,
@repository.getter('TenantConfigRepository')
protected tenantConfigRepositoryGetter: Getter<TenantConfigRepository>,
@repository.getter('UserTenantRepository')
protected userTenantRepositoryGetter: Getter<UserTenantRepository>,
@repository.getter('UserRepository')
protected userRepositoryGetter: Getter<UserRepository>,
@repository.getter('RoleRepository')
protected roleRepositoryGetter: Getter<RoleRepository>,
@repository.getter('GroupRepository')
protected groupRepositoryGetter: Getter<GroupRepository>,
@inject.getter(AuthenticationBindings.CURRENT_USER)
protected readonly getCurrentUser: Getter<
IAuthUserWithPermissions | undefined
>,
) {
super(Tenant, dataSource, getCurrentUser);
this.groups = this.createHasManyRepositoryFactoryFor(
'groups',
groupRepositoryGetter,
);
this.registerInclusionResolver('groups', this.groups.inclusionResolver);
this.roles = this.createHasManyRepositoryFactoryFor(
'roles',
roleRepositoryGetter,
);
this.registerInclusionResolver('roles', this.roles.inclusionResolver);
this.users = this.createHasManyRepositoryFactoryFor(
'users',
userRepositoryGetter,
);
this.registerInclusionResolver('users', this.users.inclusionResolver);
this.userTenants = this.createHasManyRepositoryFactoryFor(
'userTenants',
userTenantRepositoryGetter,
);
this.registerInclusionResolver(
'userTenants',
this.userTenants.inclusionResolver,
);
this.tenantConfigs = this.createHasManyRepositoryFactoryFor(
'tenantConfigs',
tenantConfigRepositoryGetter,
);
this.registerInclusionResolver(
'tenantConfigs',
this.tenantConfigs.inclusionResolver,
);
}
}