-
Notifications
You must be signed in to change notification settings - Fork 70
/
group.repository.ts
52 lines (50 loc) · 1.5 KB
/
group.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
// 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,
tenantGuard,
} from '@sourceloop/core';
import {AuthenticationBindings} from 'loopback4-authentication';
import {UserTenantDataSourceName} from '../keys';
import {Group, GroupRelations, UserGroup} from '../models';
import {UserGroupRepository} from './user-group.repository';
@tenantGuard()
export class GroupRepository extends DefaultUserModifyCrudRepository<
Group,
typeof Group.prototype.id,
GroupRelations
> {
public readonly userGroups: HasManyRepositoryFactory<
UserGroup,
typeof Group.prototype.id
>;
constructor(
@inject(`datasources.${UserTenantDataSourceName}`)
dataSource: juggler.DataSource,
@repository.getter('UserGroupRepository')
protected userGroupRepositoryGetter: Getter<UserGroupRepository>,
@inject.getter(AuthenticationBindings.CURRENT_USER)
protected readonly getCurrentUser: Getter<
IAuthUserWithPermissions | undefined
>,
) {
super(Group, dataSource, getCurrentUser);
this.userGroups = this.createHasManyRepositoryFactoryFor(
'userGroups',
userGroupRepositoryGetter,
);
this.registerInclusionResolver(
'userGroups',
this.userGroups.inclusionResolver,
);
}
}