Skip to content

Commit d0f032c

Browse files
FEAT: add tenant module
1 parent c0ec4c5 commit d0f032c

File tree

10 files changed

+46
-27
lines changed

10 files changed

+46
-27
lines changed

src/authorization/authorization.module.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ import { UserService } from './service/user.service';
5151
import { UserServiceInterface } from './service/user.service.interface';
5252
import { UserCacheService } from './service/usercache.service';
5353
import { UserCacheServiceInterface } from './service/usercache.service.interface';
54-
import Tenant from './entity/tenant.entity';
55-
import { TenantResolver } from './resolver/tenant.resolver';
56-
import TenantService from './service/tenant.service';
57-
import { TenantRepository } from './repository/tenant.repository';
58-
import { TenantServiceInterface } from './service/tenant.service.interface';
54+
import { TenantModule } from '../tenant/tenant.module';
5955

6056
@Module({
6157
imports: [
@@ -71,8 +67,8 @@ import { TenantServiceInterface } from './service/tenant.service.interface';
7167
Role,
7268
GroupRole,
7369
RolePermission,
74-
Tenant,
7570
]),
71+
TenantModule,
7672
RedisCacheModule,
7773
],
7874
providers: [
@@ -97,8 +93,6 @@ import { TenantServiceInterface } from './service/tenant.service.interface';
9793
UserGroupRepository,
9894
EntityPermissionRepository,
9995
LoggerService,
100-
TenantResolver,
101-
TenantRepository,
10296
{
10397
provide: EntityServiceInterface,
10498
useClass: EntityService,
@@ -135,10 +129,6 @@ import { TenantServiceInterface } from './service/tenant.service.interface';
135129
provide: UserCacheServiceInterface,
136130
useClass: UserCacheService,
137131
},
138-
{
139-
provide: TenantServiceInterface,
140-
useClass: TenantService,
141-
},
142132
],
143133
exports: [
144134
{

src/schema/graphql.schema.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ export interface RoleSearchCondition {
166166
name?: StringSearchCondition;
167167
}
168168

169-
export interface NewTenantInput {
170-
name: string;
171-
domain: string;
172-
}
173-
174169
export interface UpdateUserInput {
175170
firstName?: string;
176171
middleName?: string;
@@ -233,6 +228,11 @@ export interface PaginationInput {
233228
offset?: number;
234229
}
235230

231+
export interface NewTenantInput {
232+
name: string;
233+
domain: string;
234+
}
235+
236236
export interface Paginated {
237237
totalCount?: number;
238238
}
@@ -266,11 +266,11 @@ export interface IMutation {
266266
updateRole(id: string, input: UpdateRoleInput): Role | Promise<Role>;
267267
deleteRole(id: string): Role | Promise<Role>;
268268
updateRolePermissions(id: string, input: UpdateRolePermissionInput): Permission[] | Promise<Permission[]>;
269-
createTenant(input: NewTenantInput): Tenant | Promise<Tenant>;
270269
updateUser(id: string, input: UpdateUserInput): User | Promise<User>;
271270
deleteUser(id: string): User | Promise<User>;
272271
updateUserPermissions(id: string, input: UpdateUserPermissionInput): Permission[] | Promise<Permission[]>;
273272
updateUserGroups(id: string, input: UpdateUserGroupInput): UserGroupResponse[] | Promise<UserGroupResponse[]>;
273+
createTenant(input: NewTenantInput): Tenant | Promise<Tenant>;
274274
}
275275

276276
export interface TokenResponse {
@@ -357,12 +357,6 @@ export interface RolePaginated extends Paginated {
357357
results?: Role[];
358358
}
359359

360-
export interface Tenant {
361-
id: string;
362-
name: string;
363-
domain: string;
364-
}
365-
366360
export interface UserPaginated extends Paginated {
367361
totalCount?: number;
368362
results?: User[];
@@ -385,3 +379,9 @@ export interface UserGroupResponse {
385379
id: string;
386380
name: string;
387381
}
382+
383+
export interface Tenant {
384+
id: string;
385+
name: string;
386+
domain: string;
387+
}

src/authorization/entity/tenant.entity.ts renamed to src/tenant/entity/tenant.entity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
2-
import BaseEntity from './base.entity';
2+
import BaseEntity from '../../authorization/entity/base.entity';
33

44
@Entity()
55
class Tenant extends BaseEntity {

src/authorization/repository/tenant.repository.ts renamed to src/tenant/repository/tenant.repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable } from '@nestjs/common';
22
import { DataSource } from 'typeorm';
33

4-
import { BaseRepository } from './base.repository';
4+
import { BaseRepository } from '../../authorization/repository/base.repository';
55
import Tenant from '../entity/tenant.entity';
66

77
@Injectable()

src/authorization/service/tenant.service.ts renamed to src/tenant/service/tenant.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import Tenant from '../entity/tenant.entity';
44
import { TenantNotFoundException } from '../exception/tenant.exception';
55
import { TenantRepository } from '../repository/tenant.repository';
66
import { NewTenantInput } from '../../schema/graphql.schema';
7+
import { TenantServiceInterface } from './tenant.service.interface';
78

89
@Injectable()
9-
export default class TenantService {
10+
export default class TenantService implements TenantServiceInterface {
1011
constructor(private tenantRepository: TenantRepository) {}
1112

1213
async getTenantByDomain(domain: string): Promise<Tenant> {

src/tenant/tenant.module.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Module } from '@nestjs/common';
2+
import { ConfigService } from '@nestjs/config';
3+
import { TypeOrmModule } from '@nestjs/typeorm';
4+
import Tenant from '../tenant/entity/tenant.entity';
5+
import { TenantResolver } from '../tenant/resolver/tenant.resolver';
6+
import TenantService from '../tenant/service/tenant.service';
7+
import { TenantRepository } from '../tenant/repository/tenant.repository';
8+
import { TenantServiceInterface } from '../tenant/service/tenant.service.interface';
9+
10+
@Module({
11+
imports: [TypeOrmModule.forFeature([Tenant])],
12+
providers: [
13+
ConfigService,
14+
TenantResolver,
15+
TenantRepository,
16+
{
17+
provide: TenantServiceInterface,
18+
useClass: TenantService,
19+
},
20+
],
21+
exports: [
22+
{
23+
provide: TenantServiceInterface,
24+
useClass: TenantService,
25+
},
26+
],
27+
})
28+
export class TenantModule {}

0 commit comments

Comments
 (0)