Skip to content

Commit

Permalink
feat(rest-api-client): update space.getSpace method (#2876)
Browse files Browse the repository at this point in the history
  • Loading branch information
shabaraba authored Jul 25, 2024
1 parent 2a298e1 commit 8ecc4d1
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 3 deletions.
34 changes: 33 additions & 1 deletion packages/rest-api-client/docs/space.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Space

- [getSpace](#getSpace)
- [updateSpace](#updateSpace)
- [deleteSpace](#deleteSpace)
- [updateSpaceBody](#updateSpaceBody)
- [getSpaceMembers](#getSpaceMembers)
Expand Down Expand Up @@ -64,7 +65,7 @@ Gets general information of a space.
| body | String | The HTML of the Space body. |
| useMultiThread | Boolean | The "Enable multiple threads." setting.<br /><strong>true</strong>: The Space is a Multi-threaded Space.<br /><strong>false</strong>: The Space is a Single-threaded Space. |
| isGuest | Boolean | The Guest Space setting.<br /><strong>true</strong>: The Space is a Guest Space.<br /><strong>false</strong>: The Space is not a Guest Space. |
| attachedApps | Object | A list of Apps that are in the thread.<br />This does not include Apps that are not live yet. |
| attachedApps | Array | A list of Apps that are in the thread.<br />This does not include Apps that are not live yet. |
| attachedApps[].threadId | String | The Thread ID of the thread that the App was created in.<br />Apps that are created inside Spaces using the GUI will be automatically allocated to the default Thread. |
| attachedApps[].appId | String | The App ID. |
| attachedApps[].code | String | The App Code of the App.<br />An empty string is returned if an App Code is not set in the App's settings. |
Expand All @@ -84,11 +85,42 @@ Gets general information of a space.
| showAppList | Boolean | The display status for the Apps widget.<br /><strong>true</strong>: The Apps widget is displayed.<br /><strong>false</strong>: The Apps widget is not displayed.<br /><strong>null</strong> is returned for Spaces with the Enable multiple threads option turned off. |
| showMemberList | Boolean | The display status for the People widget.<br /><strong>true</strong>: The People widget is displayed.<br /><strong>false</strong>: The People widget is not displayed.<br /><strong>null</strong> is returned for Spaces with the Enable multiple threads option turned off. |
| showRelatedLinkList | Boolean | The display status for the Related Apps & Spaces widget.<br /><strong>true</strong>: The Related Apps & Spaces widget is displayed.<br /><strong>false</strong>: The Related Apps & Spaces widget is not displayed.<br /><strong>null</strong> is returned for Spaces with the Enable multiple threads option turned off. |
| permissions | Object | An object containing information of the space's permission settings. |
| permissions.createApp | String | The option set for the Only Allow Space Administrators to Create Apps setting. <br /><strong>EVERYONE</strong>: all users can create Apps. <br /><strong>ADMIN</strong>: only administrators can create Apps. |

#### Reference

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

### updateSpace

Updates the settings of a Space.

#### Parameters

| Name | Type | Required | Description |
| --------------------- | :--------------: | :------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id | Number or String | Yes | The space ID. |
| name | String | | The new name of the space. |
| isPrivate | Boolean | | The "Private" settings of the Space.<br /><strong>true</strong>: The Space is private.<br /><strong>false</strong>: The Space is not private. |
| fixedMember | Boolean | | The "Block users from joining or leaving the space and following or unfollowing the threads." setting.<br /><strong>true</strong>: Users cannot join/leave the Space or follow/unfollow threads.<br /><strong>false</strong>: Users can join/leave the Space and follow/unfollow threads. |
| useMultiThread | Boolean | | The Enable multiple threads setting.<br /><strong>true</strong>: The Space is a Multi-threaded Space.<br />If this parameter is ignored or false is specified, this parameter will not be updated. |
| showAnnouncement | Boolean | | The display status for the Announcement widget.<br /><strong>true</strong>: The Announcement widget is displayed.<br /><strong>false</strong>: The Announcement widget is not displayed. |
| showThreadList | Boolean | | The display status for the Threads widget.<br /><strong>true</strong>: The Threads widget is displayed.<br /><strong>false</strong>: The Threads widget is not displayed. |
| showAppList | Boolean | | The display status for the Apps widget.<br /><strong>true</strong>: The Apps widget is displayed.<br /><strong>false</strong>: The Apps widget is not displayed. |
| showMemberList | Boolean | | The display status for the People widget.<br /><strong>true</strong>: The People widget is displayed.<br /><strong>false</strong>: The People widget is not displayed. |
| showRelatedLinkList | Boolean | | The display status for the Related Apps & Spaces widget.<br /><strong>true</strong>: The Related Apps & Spaces widget is displayed.<br /><strong>false</strong>: The Related Apps & Spaces widget is not displayed. |
| permissions | Object | | An object containing information of the space's permission settings. |
| permissions.createApp | String | | The option set for the Only Allow Space Administrators to Create Apps setting.<br /><strong>EVERYONE</strong>: all users can create apps.<br /><strong>ADMIN</strong>: only administrators can create apps. |

#### Returns

An empty object.

#### Reference

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

### deleteSpace

Deletes a space.
Expand Down
10 changes: 9 additions & 1 deletion packages/rest-api-client/src/client/SpaceClient.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type {
SpaceID,
ThreadID,
Space,
ThreadComment,
SpaceMemberForResponse,
SpaceMemberForRequest,
GuestSpaceID,
Guest,
SpaceTemplateID,
UpdateSpaceForRequest,
Space,
} from "./types";
import { BaseClient } from "./BaseClient";

Expand All @@ -19,6 +20,13 @@ export class SpaceClient extends BaseClient {
return this.client.get(path, params);
}

public updateSpace(params: UpdateSpaceForRequest): Promise<{}> {
const path = this.buildPathWithGuestSpaceId({
endpointName: "space",
});
return this.client.put(path, params);
}

public deleteSpace(params: { id: SpaceID }): Promise<{}> {
const path = this.buildPathWithGuestSpaceId({
endpointName: "space",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { MockClient } from "../../http/MockClient";
import { buildMockClient } from "../../http/MockClient";
import { SpaceClient } from "../SpaceClient";
import { KintoneRequestConfigBuilder } from "../../KintoneRequestConfigBuilder";
import type { ThreadComment } from "../types";
import type { ThreadComment, UpdateSpaceForRequest } from "../types";

const SPACE_ID = 1;
const SPACE_TEMPLATE_ID = 1;
Expand Down Expand Up @@ -39,6 +39,36 @@ describe("SpaceClient", () => {
});
});

describe("updateSpace", () => {
const params = {
id: SPACE_ID,
name: "updated",
isPrivate: false,
useMultiThread: false,
fixedMember: false,
showAnnouncement: false,
showThreadList: false,
showAppList: false,
showMemberList: false,
showRelatedLinkList: false,
permissions: {
createApp: "EVERYONE",
},
} as UpdateSpaceForRequest;
beforeEach(async () => {
await spaceClient.updateSpace(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/k/v1/space.json");
});
it("should send a PUT request", () => {
expect(mockClient.getLogs()[0].method).toBe("put");
});
it("should pass params to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});

describe("deleteSpace", () => {
const params = {
id: SPACE_ID,
Expand Down
24 changes: 24 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 @@ -15,6 +15,10 @@ type AttachedApp = Pick<
| "modifier"
>;

type Permissions = {
createApp: "EVERYONE" | "ADMIN";
};

export type Space = {
id: string;
name: string;
Expand All @@ -31,6 +35,26 @@ export type Space = {
isGuest: boolean;
attachedApps: AttachedApp[];
fixedMember: boolean;
showAnnouncement: boolean | null;
showThreadList: boolean | null;
showAppList: boolean | null;
showMemberList: boolean | null;
showRelatedLinkList: boolean | null;
permissions: Permissions;
};

export type UpdateSpaceForRequest = {
id: SpaceID;
name?: string;
isPrivate?: boolean;
useMultiThread?: boolean;
fixedMember?: boolean;
showAnnouncement?: boolean;
showThreadList?: boolean;
showAppList?: boolean;
showMemberList?: boolean;
showRelatedLinkList?: boolean;
permissions?: Permissions;
};

export type SpaceMemberForResponse = {
Expand Down

0 comments on commit 8ecc4d1

Please sign in to comment.