mirror of
https://github.com/bitwarden/browser
synced 2026-02-26 09:33:22 +00:00
[EC-86] Refactor/rename GroupApiService
- Re-name GroupApiService to GroupService as there is no need for a separate Api service (no sync or local data for admin services) - Add GroupView for use in the GroupService instead of raw API models - Update views to use GroupView instead of raw GroupResponse models
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
import {
|
||||
GroupDetailsResponse,
|
||||
GroupResponse,
|
||||
} from "@bitwarden/common/abstractions/group/responses/groupResponse";
|
||||
import { ListResponse } from "@bitwarden/common/models/response/listResponse";
|
||||
|
||||
export class GroupApiServiceAbstraction {
|
||||
delete: (orgId: string, groupId: string) => Promise<void>;
|
||||
deleteMany: (orgId: string, groupIds: string[]) => Promise<ListResponse<GroupResponse>>;
|
||||
|
||||
get: (orgId: string, groupId: string) => Promise<GroupDetailsResponse>;
|
||||
getAll: (orgId: string) => Promise<ListResponse<GroupDetailsResponse>>;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { GroupView } from "@bitwarden/common/models/view/groupView";
|
||||
|
||||
export class GroupServiceAbstraction {
|
||||
delete: (orgId: string, groupId: string) => Promise<void>;
|
||||
deleteMany: (orgId: string, groupIds: string[]) => Promise<GroupView[]>;
|
||||
|
||||
get: (orgId: string, groupId: string) => Promise<GroupView>;
|
||||
getAll: (orgId: string) => Promise<GroupView[]>;
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from "./group-api.service.abstraction";
|
||||
export * from "./group.service.abstraction";
|
||||
export * from "./responses/groupResponse";
|
||||
|
||||
17
libs/common/src/models/view/groupView.ts
Normal file
17
libs/common/src/models/view/groupView.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { GroupResponse } from "@bitwarden/common/abstractions/group";
|
||||
import { SelectionReadOnlyResponse } from "@bitwarden/common/models/response/selectionReadOnlyResponse";
|
||||
|
||||
import { View } from "./view";
|
||||
|
||||
export class GroupView implements View {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
name: string;
|
||||
accessAll: boolean;
|
||||
externalId: string;
|
||||
collections: SelectionReadOnlyResponse[] = [];
|
||||
|
||||
static fromResponse(response: GroupResponse) {
|
||||
return Object.assign(new GroupView(), response);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||
import {
|
||||
GroupApiServiceAbstraction,
|
||||
GroupDetailsResponse,
|
||||
GroupResponse,
|
||||
GroupServiceAbstraction,
|
||||
} from "@bitwarden/common/abstractions/group";
|
||||
import { OrganizationGroupBulkRequest } from "@bitwarden/common/models/request/OrganizationGroupBulkRequest";
|
||||
import { ListResponse } from "@bitwarden/common/models/response/listResponse";
|
||||
import { GroupView } from "@bitwarden/common/models/view/groupView";
|
||||
|
||||
export class GroupApiService implements GroupApiServiceAbstraction {
|
||||
export class GroupService implements GroupServiceAbstraction {
|
||||
constructor(private apiService: ApiService) {}
|
||||
|
||||
async delete(orgId: string, groupId: string): Promise<void> {
|
||||
@@ -20,7 +21,7 @@ export class GroupApiService implements GroupApiServiceAbstraction {
|
||||
);
|
||||
}
|
||||
|
||||
async deleteMany(orgId: string, groupIds: string[]): Promise<ListResponse<GroupResponse>> {
|
||||
async deleteMany(orgId: string, groupIds: string[]): Promise<GroupView[]> {
|
||||
const request = new OrganizationGroupBulkRequest(groupIds);
|
||||
|
||||
const r = await this.apiService.send(
|
||||
@@ -30,11 +31,12 @@ export class GroupApiService implements GroupApiServiceAbstraction {
|
||||
true,
|
||||
true
|
||||
);
|
||||
const listResponse = new ListResponse(r, GroupResponse);
|
||||
|
||||
return new ListResponse(r, GroupResponse);
|
||||
return listResponse.data?.map((gr) => GroupView.fromResponse(gr)) ?? [];
|
||||
}
|
||||
|
||||
async get(orgId: string, groupId: string): Promise<GroupDetailsResponse> {
|
||||
async get(orgId: string, groupId: string): Promise<GroupView> {
|
||||
const r = await this.apiService.send(
|
||||
"GET",
|
||||
"/organizations/" + orgId + "/groups/" + groupId + "/details",
|
||||
@@ -43,10 +45,10 @@ export class GroupApiService implements GroupApiServiceAbstraction {
|
||||
true
|
||||
);
|
||||
|
||||
return new GroupDetailsResponse(r);
|
||||
return GroupView.fromResponse(new GroupDetailsResponse(r));
|
||||
}
|
||||
|
||||
async getAll(orgId: string): Promise<ListResponse<GroupDetailsResponse>> {
|
||||
async getAll(orgId: string): Promise<GroupView[]> {
|
||||
const r = await this.apiService.send(
|
||||
"GET",
|
||||
"/organizations/" + orgId + "/groups",
|
||||
@@ -55,6 +57,8 @@ export class GroupApiService implements GroupApiServiceAbstraction {
|
||||
true
|
||||
);
|
||||
|
||||
return new ListResponse(r, GroupDetailsResponse);
|
||||
const listResponse = new ListResponse(r, GroupDetailsResponse);
|
||||
|
||||
return listResponse.data?.map((gr) => GroupView.fromResponse(gr)) ?? [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user