Skip to content

Commit d9fd3d6

Browse files
feat: TT-188 add & remove groups to user service
1 parent e82a479 commit d9fd3d6

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/app/modules/users/models/users.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ export interface User {
22
name: string;
33
email: string;
44
roles?: string[];
5+
groups?: string[];
56
id: string;
67
tenant_id?: string;
78
deleted?: string;
89
}
10+
11+
export interface UserState extends User {
12+
isLoading: boolean;
13+
error: string;
14+
}

src/app/modules/users/services/users.service.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,24 @@ describe('UsersService', () => {
5151
const grantRoleRequest = httpMock.expectOne(`${service.baseUrl}/${userId}/roles/${roleId}/revoke`);
5252
expect(grantRoleRequest.request.method).toBe('POST');
5353
});
54+
55+
it('add group to a User', () => {
56+
const userId = 'userId';
57+
const group = 'admin';
58+
const addGroupURL = `${service.baseUrl}/${userId}/groups/add`;
59+
60+
service.addGroupToUser(userId, group).subscribe();
61+
62+
expect(httpMock.expectOne(addGroupURL).request.method).toBe('POST');
63+
});
64+
65+
it('remove group to a User', () => {
66+
const userId = 'userId';
67+
const group = 'admin';
68+
const removeGroupURL = `${service.baseUrl}/${userId}/groups/remove`;
69+
70+
service.removeGroupToUser(userId, group).subscribe();
71+
72+
expect(httpMock.expectOne(removeGroupURL).request.method).toBe('POST');
73+
});
5474
});

src/app/modules/users/services/users.service.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { HttpClient } from '@angular/common/http';
22
import { Injectable } from '@angular/core';
33
import { Observable } from 'rxjs';
4+
import { User } from '../models/users';
45
import { environment } from './../../../../environments/environment';
56
@Injectable({
67
providedIn: 'root',
@@ -23,4 +24,16 @@ export class UsersService {
2324
const url = `${this.baseUrl}/${userId}/roles/${roleId}/revoke`;
2425
return this.http.post(url, null);
2526
}
27+
28+
addGroupToUser(userId: string, group: string): Observable<User> {
29+
return this.http.post<User>(`${this.baseUrl}/${userId}/groups/add`, {
30+
group_name: group,
31+
});
32+
}
33+
34+
removeGroupToUser(userId: string, group: string): Observable<User> {
35+
return this.http.post<User>(`${this.baseUrl}/${userId}/groups/remove`, {
36+
group_name: group,
37+
});
38+
}
2639
}

0 commit comments

Comments
 (0)