Skip to content

Commit 5e0b2a6

Browse files
REFACTOR: remove tenantId in response
1 parent 7572a60 commit 5e0b2a6

File tree

11 files changed

+47
-78
lines changed

11 files changed

+47
-78
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ 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';
2928

3029
@Injectable()
3130
export default class PasswordAuthService implements Authenticatable {
@@ -69,7 +68,6 @@ export default class PasswordAuthService implements Authenticatable {
6968
async inviteTokenSignup(
7069
userDetails: UserInviteTokenSignupInput,
7170
): Promise<InviteTokenResponse> {
72-
const tenantId = ExecutionManager.getTenantId();
7371
const verifyUser = await this.userService.verifyDuplicateUser(
7472
userDetails.email,
7573
userDetails.phone,
@@ -87,7 +85,6 @@ export default class PasswordAuthService implements Authenticatable {
8785
userFromInput.middleName = userDetails.middleName;
8886
userFromInput.lastName = userDetails.lastName;
8987
userFromInput.status = Status.INVITED;
90-
userFromInput.tenantId = tenantId;
9188
let invitationToken: { token: any; tokenExpiryTime?: any };
9289
const transaction = await this.dataSource.manager.transaction(async () => {
9390
const savedUser = await this.userService.createUser(userFromInput);
@@ -107,7 +104,6 @@ export default class PasswordAuthService implements Authenticatable {
107104
lastName: user.lastName,
108105
inviteToken: user?.inviteToken,
109106
status: user.status,
110-
tenantId: user.tenantId,
111107
};
112108
return {
113109
inviteToken: invitationToken.token,

src/authorization/graphql/entity.graphql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
type Entity {
22
id: ID!
33
name: String!
4-
tenantId: String!
54
permissions: [Permission]
65
}
76

src/authorization/graphql/group.graphql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
type Group {
22
id: ID!
33
name: String!
4-
tenantId: String!
54
users: [User]
65
roles: [Role]
76
permissions: [Permission]
@@ -28,7 +27,6 @@ input UpdateGroupRoleInput {
2827
type GroupRole {
2928
id: ID!,
3029
name: String!
31-
tenantId: String!
3230
}
3331

3432
input GroupInputFilter {

src/authorization/graphql/role.graphql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
type Role {
22
id: ID!
33
name: String!
4-
tenantId: String!
54
permissions: [Permission]
65
}
76

src/authorization/graphql/user.graphql

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

2625
enum OperationType {
@@ -45,7 +44,6 @@ input UpdateUserGroupInput {
4544
type UserGroupResponse {
4645
id: ID!,
4746
name: String!
48-
tenantId: String!
4947
}
5048

5149
enum OperationType {

src/schema/graphql.schema.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ export interface InviteTokenResponse {
297297
export interface Entity {
298298
id: string;
299299
name: string;
300-
tenantId: string;
301300
permissions?: Permission[];
302301
}
303302

@@ -325,7 +324,6 @@ export interface IQuery {
325324
export interface Group {
326325
id: string;
327326
name: string;
328-
tenantId: string;
329327
users?: User[];
330328
roles?: Role[];
331329
permissions?: Permission[];
@@ -335,7 +333,6 @@ export interface Group {
335333
export interface GroupRole {
336334
id: string;
337335
name: string;
338-
tenantId: string;
339336
}
340337

341338
export interface GroupPaginated extends Paginated {
@@ -352,7 +349,6 @@ export interface Permission {
352349
export interface Role {
353350
id: string;
354351
name: string;
355-
tenantId: string;
356352
permissions?: Permission[];
357353
}
358354

@@ -383,11 +379,9 @@ export interface User {
383379
groups?: Group[];
384380
permissions?: Permission[];
385381
inviteToken?: string;
386-
tenantId: string;
387382
}
388383

389384
export interface UserGroupResponse {
390385
id: string;
391386
name: string;
392-
tenantId: string;
393387
}

test/authentication/resolver/userauth.resolver.test.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ describe('Userauth Module', () => {
9595
firstName: users[0].firstName,
9696
lastName: users[0].lastName,
9797
status: users[0].status,
98-
tenantId: users[0].tenantId,
9998
};
10099
const tokenResponse = {
101100
accessToken: `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
@@ -116,7 +115,7 @@ describe('Userauth Module', () => {
116115
.post(gql)
117116
.send({
118117
query:
119-
'mutation { passwordLogin(input: { username: "[email protected]" password: "s3cr3t1234567890" }) { accessToken, refreshToken, user{ id, email, phone, firstName, lastName, status tenantId} }}',
118+
'mutation { passwordLogin(input: { username: "[email protected]" password: "s3cr3t1234567890" }) { accessToken, refreshToken, user{ id, email, phone, firstName, lastName, status}}}',
120119
})
121120
.expect(200)
122121
.expect((res) => {
@@ -186,7 +185,6 @@ describe('Userauth Module', () => {
186185
inviteToken:
187186
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Inh5ekBrZXl2YWx1ZS5zeXN0ZW1zIiwiaWF0IjoxNjIxNTI1NTE1LCJleHAiOjE2MjE1MjkxMTV9.t8z7rBZKkog-1jirScYU6HE7KVTzatKWjZw8lVz3xLo',
188187
status: Status.INVITED,
189-
tenantId: users[0].tenantId,
190188
},
191189
};
192190
configService.get('JWT_SECRET').returns('s3cr3t1234567890');
@@ -202,7 +200,7 @@ describe('Userauth Module', () => {
202200
.set('Authorization', `Bearer ${token}`)
203201
.send({
204202
query: `mutation { inviteTokenSignup(input: { email: "[email protected]"
205-
phone: "9947849200" firstName: "Test" lastName: "Name" }) { inviteToken tokenExpiryTime user{id firstName lastName inviteToken status tenantId}}}`,
203+
phone: "9947849200" firstName: "Test" lastName: "Name" }) { inviteToken tokenExpiryTime user{id firstName lastName inviteToken status}}}`,
206204
})
207205
.expect(200)
208206
.expect((res) => {
@@ -286,7 +284,6 @@ describe('Userauth Module', () => {
286284
inviteToken:
287285
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Inh5ekBrZXl2YWx1ZS5zeXN0ZW1zIiwiaWF0IjoxNjIxNTI1NTE1LCJleHAiOjE2MjE1MjkxMTV9.t8z7rBZKkog-1jirScYU6HE7KVTzatKWjZw8lVz3xLo',
288286
status: Status.INVITED,
289-
tenantId: users[0].tenantId,
290287
},
291288
};
292289
tokenService
@@ -307,7 +304,6 @@ describe('Userauth Module', () => {
307304
lastName
308305
inviteToken
309306
status
310-
tenantId
311307
}
312308
}
313309
}`,
@@ -345,7 +341,6 @@ describe('Userauth Module', () => {
345341
firstName: users[0].firstName,
346342
lastName: users[0].lastName,
347343
status: users[0].status,
348-
tenantId: users[0].tenantId,
349344
};
350345
const tokenResponse: TokenResponse = { ...token, user: user };
351346
tokenService
@@ -355,7 +350,7 @@ describe('Userauth Module', () => {
355350
return request(app.getHttpServer())
356351
.post(gql)
357352
.send({
358-
query: `mutation { refresh(input: { refreshToken: "${token.refreshToken}"}) { accessToken refreshToken user { id, email, phone, firstName, lastName, status tenantId} }}`,
353+
query: `mutation { refresh(input: { refreshToken: "${token.refreshToken}"}) { accessToken refreshToken user { id, email, phone, firstName, lastName, status}}}`,
359354
})
360355
.expect(200)
361356
.expect((res) => {

test/authorization/resolver/entity.resolver.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
UpdateEntityPermissionInput,
1818
} from '../../../src/schema/graphql.schema';
1919
import { mockedConfigService } from '../../utils/mocks/config.service';
20+
import EntityModel from '../../../src/authorization/entity/entity.entity';
2021

2122
const gql = '/graphql';
2223

@@ -46,15 +47,13 @@ const allEntities: Entity[] = [
4647
id: '2b33268a-7ff5-4cac-a87a-6bfc4430d34c',
4748
name: 'Customers',
4849
permissions: permissions,
49-
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
5050
},
5151
];
5252

5353
const entities: Entity[] = [
5454
{
5555
id: '2b33268a-7ff5-4cac-a87a-6bfc4430d34c',
5656
name: 'Customers',
57-
tenantId: '1ef2a357-d4b7-4a30-88ca-d1cc627f2994',
5857
},
5958
];
6059

@@ -94,15 +93,17 @@ describe('Entity Module', () => {
9493
describe(gql, () => {
9594
describe('entities', () => {
9695
it('should get the entities', () => {
97-
entityService.getAllEntities().returns(Promise.resolve(entities));
96+
entityService
97+
.getAllEntities()
98+
.returns(Promise.resolve(entities as EntityModel[]));
9899
entityService
99100
.getEntityPermissions('2b33268a-7ff5-4cac-a87a-6bfc4430d34c')
100101
.returns(Promise.resolve(permissions));
101102
return request(app.getHttpServer())
102103
.post(gql)
103104
.set('Authorization', `Bearer ${token}`)
104105
.send({
105-
query: '{getEntities {id name permissions { id name} tenantId}}',
106+
query: '{getEntities {id name permissions { id name}}}',
106107
})
107108
.expect(200)
108109
.expect((res) => {
@@ -113,13 +114,13 @@ describe('Entity Module', () => {
113114
it('should get single entity', () => {
114115
entityService
115116
.getEntityById('ae032b1b-cc3c-4e44-9197-276ca877a7f8')
116-
.returns(Promise.resolve(entities[0]));
117+
.returns(Promise.resolve(entities[0] as EntityModel));
117118
return request(app.getHttpServer())
118119
.post(gql)
119120
.set('Authorization', `Bearer ${token}`)
120121
.send({
121122
query:
122-
'{getEntity(id: "ae032b1b-cc3c-4e44-9197-276ca877a7f8") {id name tenantId}}',
123+
'{getEntity(id: "ae032b1b-cc3c-4e44-9197-276ca877a7f8") {id name}}',
123124
})
124125
.expect(200)
125126
.expect((res) => {
@@ -134,13 +135,12 @@ describe('Entity Module', () => {
134135
const obj = Object.create(null);
135136
entityService
136137
.createEntity(Object.assign(obj, input))
137-
.returns(Promise.resolve(entities[0]));
138+
.returns(Promise.resolve(entities[0] as EntityModel));
138139
return request(app.getHttpServer())
139140
.post(gql)
140141
.set('Authorization', `Bearer ${token}`)
141142
.send({
142-
query:
143-
'mutation { createEntity(input: {name: "Test1"}) {id name tenantId}}',
143+
query: 'mutation { createEntity(input: {name: "Test1"}) {id name}}',
144144
})
145145
.expect(200)
146146
.expect((res) => {
@@ -158,13 +158,13 @@ describe('Entity Module', () => {
158158
'ae032b1b-cc3c-4e44-9197-276ca877a7f8',
159159
Object.assign(obj, input),
160160
)
161-
.returns(Promise.resolve(entities[0]));
161+
.returns(Promise.resolve(entities[0] as EntityModel));
162162
return request(app.getHttpServer())
163163
.post(gql)
164164
.set('Authorization', `Bearer ${token}`)
165165
.send({
166166
query:
167-
'mutation { updateEntity(id: "ae032b1b-cc3c-4e44-9197-276ca877a7f8", input: {name: "Test1"}) {id name tenantId}}',
167+
'mutation { updateEntity(id: "ae032b1b-cc3c-4e44-9197-276ca877a7f8", input: {name: "Test1"}) {id name}}',
168168
})
169169
.expect(200)
170170
.expect((res) => {
@@ -175,13 +175,13 @@ describe('Entity Module', () => {
175175
it('should delete a entity', () => {
176176
entityService
177177
.deleteEntity('ae032b1b-cc3c-4e44-9197-276ca877a7f8')
178-
.returns(Promise.resolve(entities[0]));
178+
.returns(Promise.resolve(entities[0] as EntityModel));
179179
return request(app.getHttpServer())
180180
.post(gql)
181181
.set('Authorization', `Bearer ${token}`)
182182
.send({
183183
query:
184-
'mutation { deleteEntity(id: "ae032b1b-cc3c-4e44-9197-276ca877a7f8") {id name tenantId}}',
184+
'mutation { deleteEntity(id: "ae032b1b-cc3c-4e44-9197-276ca877a7f8") {id name}}',
185185
})
186186
.expect(200)
187187
.expect((res) => {

0 commit comments

Comments
 (0)