Skip to content

Commit

Permalink
feat(rest-api-client): add space.updateThread() method (#2606)
Browse files Browse the repository at this point in the history
Co-authored-by: hung-nguyen <[email protected]>
  • Loading branch information
tuanphamcybozu and hung-cybo authored Mar 12, 2024
1 parent ca89795 commit 139e504
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/rest-api-client-demo/src/space.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { KintoneRestAPIClient } from "@kintone/rest-api-client";

const SPACE_ID = 8;
const THREAD_ID = 8;

export class Space {
private client: KintoneRestAPIClient;
Expand Down Expand Up @@ -79,4 +80,16 @@ export class Space {
console.log(error);
}
}

public async updateThread() {
const body = "<b>This is an updated thread body</b>";
const name = "Updated Thread Name";
try {
console.log(
await this.client.space.updateThread({ id: THREAD_ID, body, name }),
);
} catch (error) {
console.log(error);
}
}
}
21 changes: 21 additions & 0 deletions packages/rest-api-client/docs/space.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [updateSpaceBody](#updateSpaceBody)
- [getSpaceMembers](#getSpaceMembers)
- [updateSpaceMembers](#updateSpaceMembers)
- [updateThread](#updateThread)

## Overview

Expand Down Expand Up @@ -168,3 +169,23 @@ An empty object.
#### Reference

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

### updateThread

Updates a Thread of a Space.

#### Parameters

| Name | Type | Required | Description |
| ---- | :--------------: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| id | Number or String | Yes | The Thread ID.<br />The Thread ID can be found in the URL of the Thread.<br />A Space with the URL of https://{domainname}.kintone.com/k/#/space/111/thread/222 has a Space ID of 111 and a Thread ID of 222. |
| name | String | | The new name of the Thread.<br />Must be between 1 - 128 characters.<br />The name will not be updated if this parameter is ignored.<br />The Thread name of single threaded Spaces cannot be updated. |
| body | String | | The contents of the Thread body.<br />Write the contents as an HTML string, within 65535 characters<br />HTML tags that cannot be used will be automatically removed.<br />HTML can be used to attach Apps, files and Emoji.<br />The usage of the @ mark to mention a user will not notify that user. |

#### Returns

An empty object.

#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/spaces/update-thread/
12 changes: 12 additions & 0 deletions packages/rest-api-client/src/client/SpaceClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {
SpaceID,
ThreadID,
Space,
SpaceMemberForResponse,
SpaceMemberForRequest,
Expand Down Expand Up @@ -46,4 +47,15 @@ export class SpaceClient extends BaseClient {
});
return this.client.put(path, params);
}

public updateThread(params: {
id: ThreadID;
name?: string;
body?: string;
}): Promise<{}> {
const path = this.buildPathWithGuestSpaceId({
endpointName: "space/thread",
});
return this.client.put(path, params);
}
}
21 changes: 21 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 @@ -4,6 +4,7 @@ import { SpaceClient } from "../SpaceClient";
import { KintoneRequestConfigBuilder } from "../../KintoneRequestConfigBuilder";

const SPACE_ID = 1;
const THREAD_ID = 1;

describe("SpaceClient", () => {
let mockClient: MockClient;
Expand Down Expand Up @@ -132,6 +133,26 @@ describe("SpaceClient", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});

describe("updateThread", () => {
const params = {
id: THREAD_ID,
name: "Updated Thread Name",
body: "<b>This is an updated thread body</b>",
};
beforeEach(async () => {
await spaceClient.updateThread(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/k/v1/space/thread.json");
});
it("should send a PUT request", () => {
expect(mockClient.getLogs()[0].method).toBe("put");
});
it("should pass id, name, body to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});
});

describe("SpaceClient with guestSpaceId", () => {
Expand Down
1 change: 1 addition & 0 deletions packages/rest-api-client/src/client/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export type AppID = string | number;
export type RecordID = string | number;
export type Revision = string | number;
export type SpaceID = string | number;
export type ThreadID = string | number;

export * from "./record";
export * from "./app";
Expand Down

0 comments on commit 139e504

Please sign in to comment.