Skip to content

Commit

Permalink
feat(rest-api-client): add space.getSpaceMembers() method (#2599)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuanphamcybozu authored Mar 8, 2024
1 parent 7a0c80a commit 2c05fa9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
8 changes: 8 additions & 0 deletions examples/rest-api-client-demo/src/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export class Space {
}
}

public async getSpaceMembers() {
try {
console.log(await this.client.space.getSpaceMembers({ id: SPACE_ID }));
} catch (error) {
console.log(error);
}
}

public async updateSpaceMembers() {
const spaceMembers = {
id: SPACE_ID,
Expand Down
27 changes: 27 additions & 0 deletions packages/rest-api-client/docs/space.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [getSpace](#getSpace)
- [deleteSpace](#deleteSpace)
- [updateSpaceBody](#updateSpaceBody)
- [getSpaceMembers](#getSpaceMembers)
- [updateSpaceMembers](#updateSpaceMembers)

## Overview
Expand Down Expand Up @@ -118,6 +119,32 @@ An empty object.

- https://kintone.dev/en/docs/kintone/rest-api/spaces/update-space-body/

### getSpaceMembers

Gets the list of Space Members of a Space.

#### Parameters

| Name | Type | Required | Description |
| ---- | :--------------: | :------: | ------------- |
| id | Number or String | Yes | The space ID. |

#### Returns

| Name | Type | Description |
| --------------------- | :-----: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| members | Array | A list of Space members.<br />Guest users, inactive users and deleted users will not be included. |
| members[].entity | Object | The entity information of the Space member. |
| members[].entity.type | String | The entity type of the Space member.<br /><br /><strong>USER</strong>: User<br /><strong>GROUP</strong>: Group<br /><strong>ORGANIZATION</strong>: Department |
| members[].entity.code | String | The code of the Space member. |
| members[].isAdmin | Boolean | The Space Admin settings of the Space member.<br /><br /><strong>true</strong>: The Space Member is the Space Administrator.<br /><strong>false</strong>: The Space Member is not the Space Administrator. |
| members[].isImplicit | Boolean | If the Space Member is added as a User or not.<br /><br /><strong>true</strong>: The Space Member is not added as a user, and is added as part of a Group or Department.<br /><strong>false</strong>: The Space Member is added as a User.<br /><br />This is not responded for <strong>GROUP</strong> and <strong>ORGANIZATION</strong> entities. |
| members[].includeSubs | Boolean | The "Include Affiliated Departments" setting of the Department Space Member.<br /><br /><strong>true</strong>: Affiliated Departments are included.<br /><strong>false</strong>: Affiliated Departments are not included. |

#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/spaces/get-space-members/

### updateSpaceMembers

Updates the members of a Space.
Expand Down
16 changes: 15 additions & 1 deletion packages/rest-api-client/src/client/SpaceClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { SpaceID, Space, SpaceMemberForRequest } from "./types";
import type {
SpaceID,
Space,
SpaceMemberForResponse,
SpaceMemberForRequest,
} from "./types";
import { BaseClient } from "./BaseClient";

export class SpaceClient extends BaseClient {
Expand All @@ -23,6 +28,15 @@ export class SpaceClient extends BaseClient {
return this.client.put(path, params);
}

public getSpaceMembers(params: {
id: SpaceID;
}): Promise<{ members: SpaceMemberForResponse[] }> {
const path = this.buildPathWithGuestSpaceId({
endpointName: "space/members",
});
return this.client.get(path, params);
}

public updateSpaceMembers(params: {
id: SpaceID;
members: SpaceMemberForRequest[];
Expand Down
18 changes: 18 additions & 0 deletions packages/rest-api-client/src/client/__tests__/SpaceClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ describe("SpaceClient", () => {
});
});

describe("getSpaceMembers", () => {
const params = {
id: SPACE_ID,
};
beforeEach(async () => {
await spaceClient.getSpaceMembers(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/k/v1/space/members.json");
});
it("should send a GET request", () => {
expect(mockClient.getLogs()[0].method).toBe("get");
});
it("should pass id as a param to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});

describe("updateSpaceMembers", () => {
const params = {
id: SPACE_ID,
Expand Down
7 changes: 7 additions & 0 deletions packages/rest-api-client/src/client/types/space/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export type Space = {
fixedMember: boolean;
};

export type SpaceMemberForResponse = {
entity: Entity;
isAdmin: boolean;
isImplicit: boolean;
includeSubs: boolean;
};

export type SpaceMemberForRequest = {
entity: Entity;
isAdmin?: boolean;
Expand Down

0 comments on commit 2c05fa9

Please sign in to comment.