Skip to content

Commit 0dbb5fe

Browse files
Merge pull request #1 from bharathkeyvalue/multi-tanent-test-fix
tests: multi-tanent test fixes
2 parents 9d7e744 + 937a1f8 commit 0dbb5fe

36 files changed

+165
-152
lines changed

package-lock.json

Lines changed: 21 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"twilio": "^3.67.1",
6666
"typeorm": "^0.3.11",
6767
"typeorm-naming-strategies": "^2.0.0",
68+
"uuid": "^8.3.2",
6869
"winston": "^3.3.3"
6970
},
7071
"devDependencies": {
@@ -86,6 +87,7 @@
8687
"@types/speakeasy": "^2.0.6",
8788
"@types/supertest": "^2.0.10",
8889
"@types/totp-generator": "0.0.2",
90+
"@types/uuid": "^10.0.0",
8991
"@typescript-eslint/eslint-plugin": "^4.19.0",
9092
"@typescript-eslint/parser": "^4.19.0",
9193
"eslint": "^7.22.0",

src/app.module.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Module } from '@nestjs/common';
1+
import { MiddlewareConsumer, Module } from '@nestjs/common';
22
import * as Joi from '@hapi/joi';
33
import { ConfigModule } from '@nestjs/config';
44

@@ -7,6 +7,7 @@ import { AppGraphQLModule } from './graphql/graphql.module';
77
import { UserAuthModule } from './authentication/authentication.module';
88
import { AuthorizationModule } from './authorization/authorization.module';
99
import { HealthModule } from './health/health.module';
10+
import { ExecutionContextBinder } from './middleware/executionId.middleware';
1011

1112
@Module({
1213
imports: [
@@ -30,4 +31,8 @@ import { HealthModule } from './health/health.module';
3031
controllers: [],
3132
providers: [],
3233
})
33-
export class AppModule {}
34+
export class AppModule {
35+
configure(consumer: MiddlewareConsumer) {
36+
consumer.apply(ExecutionContextBinder).forRoutes('*');
37+
}
38+
}

src/authentication/authentication.helper.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ export class AuthenticationHelper {
1313
this.configService.get('JWT_TOKEN_EXPTIME') * 1 || 60 * 60;
1414
const secret = this.configService.get('JWT_SECRET') as string;
1515
const username = userDetails.email || userDetails.phone;
16-
const tenantId = userDetails.tenantId;
1716
const dataStoredInToken = {
1817
username: username,
19-
tenantId,
18+
tenantId: userDetails.tenantId,
2019
sub: userDetails.id,
2120
env: this.configService.get('ENV') || 'local',
2221
};

src/authentication/service/password.auth.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from '../exception/userauth.exception';
2626
import { Authenticatable } from '../interfaces/authenticatable';
2727
import { TokenService } from './token.service';
28+
import { ExecutionManager } from '../../util/execution.manager';
2829

2930
@Injectable()
3031
export default class PasswordAuthService implements Authenticatable {
@@ -68,6 +69,7 @@ export default class PasswordAuthService implements Authenticatable {
6869
async inviteTokenSignup(
6970
userDetails: UserInviteTokenSignupInput,
7071
): Promise<InviteTokenResponse> {
72+
const tenantId = ExecutionManager.getTenantId();
7173
const verifyUser = await this.userService.verifyDuplicateUser(
7274
userDetails.email,
7375
userDetails.phone,
@@ -85,6 +87,7 @@ export default class PasswordAuthService implements Authenticatable {
8587
userFromInput.middleName = userDetails.middleName;
8688
userFromInput.lastName = userDetails.lastName;
8789
userFromInput.status = Status.INVITED;
90+
userFromInput.tenantId = tenantId;
8891
let invitationToken: { token: any; tokenExpiryTime?: any };
8992
const transaction = await this.dataSource.manager.transaction(async () => {
9093
const savedUser = await this.userService.createUser(userFromInput);
@@ -104,6 +107,7 @@ export default class PasswordAuthService implements Authenticatable {
104107
lastName: user.lastName,
105108
inviteToken: user?.inviteToken,
106109
status: user.status,
110+
tenantId: user.tenantId,
107111
};
108112
return {
109113
inviteToken: invitationToken.token,

src/authorization/entity/abstract.tenant.entity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { PrimaryColumn } from 'typeorm';
1+
import { Column } from 'typeorm';
22
import BaseEntity from './base.entity';
33

44
class AbstractTenantEntity extends BaseEntity {
5-
@PrimaryColumn({ type: 'uuid' })
5+
@Column({ type: 'uuid' })
66
public tenantId!: string;
77
}
88

src/authorization/graphql/entity.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
type Entity {
22
id: ID!
33
name: String!
4+
tenantId: String!
45
permissions: [Permission]
56
}
67

src/authorization/graphql/group.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
type Group {
22
id: ID!
33
name: String!
4+
tenantId: String!
45
users: [User]
56
roles: [Role]
67
permissions: [Permission]
@@ -27,6 +28,7 @@ input UpdateGroupRoleInput {
2728
type GroupRole {
2829
id: ID!,
2930
name: String!
31+
tenantId: String!
3032
}
3133

3234
input GroupInputFilter {

src/authorization/graphql/role.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
type Role {
22
id: ID!
33
name: String!
4+
tenantId: String!
45
permissions: [Permission]
56
}
67

src/authorization/graphql/user.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type User {
2020
groups: [Group]
2121
permissions: [Permission]
2222
inviteToken: String
23+
tenantId: String!
2324
}
2425

2526
enum OperationType {
@@ -44,6 +45,7 @@ input UpdateUserGroupInput {
4445
type UserGroupResponse {
4546
id: ID!,
4647
name: String!
48+
tenantId: String!
4749
}
4850

4951
enum OperationType {

0 commit comments

Comments
 (0)