Skip to content

Commit

Permalink
feat(rest-api-client): add space.addThread() method (#2846)
Browse files Browse the repository at this point in the history
  • Loading branch information
shabaraba authored Jul 9, 2024
1 parent 099c5f3 commit e08575a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/rest-api-client-demo/src/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ export class Space {
}
}

public async addThread() {
const name = "The thread added via rest-api-client";
try {
console.log(await this.client.space.addThread({ space: SPACE_ID, name }));
} catch (error) {
console.log(error);
}
}

public async updateThread() {
const body = "<b>This is an updated thread body</b>";
const name = "Updated Thread Name";
Expand Down
23 changes: 23 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)
- [addThread](#addThread)
- [updateThread](#updateThread)
- [addThreadComment](#addThreadComment)
- [addGuests](#addGuests)
Expand Down Expand Up @@ -175,6 +176,28 @@ An empty object.

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

### addThread

Adds a Thread of a Space.<br />
The Enable multiple threads option must be enabled in the space settings.

#### Parameters

| Name | Type | Required | Description |
| ----- | :--------------: | :------: | -------------------------------------------------------------------- |
| space | Number or String | Yes | The space ID. |
| name | String | Yes | The new name of the Thread.<br />Must be between 1 - 128 characters. |

#### Returns

| Name | Type | Description |
| ---- | :----: | ------------------------------------ |
| id | String | The thread ID of the created Thread. |

#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/spaces/add-thread/

### updateThread

Updates a Thread of a Space.
Expand Down
10 changes: 10 additions & 0 deletions packages/rest-api-client/src/client/SpaceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ export class SpaceClient extends BaseClient {
return this.client.put(path, params);
}

public addThread(params: {
space: SpaceID;
name: string;
}): Promise<{ id: string }> {
const path = this.buildPathWithGuestSpaceId({
endpointName: "space/thread",
});
return this.client.post(path, params);
}

public updateThread(params: {
id: ThreadID;
name?: string;
Expand Down
19 changes: 19 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 @@ -136,6 +136,25 @@ describe("SpaceClient", () => {
});
});

describe("addThread", () => {
const params = {
space: SPACE_ID,
name: "Added Thread Name",
};
beforeEach(async () => {
await spaceClient.addThread(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 POST request", () => {
expect(mockClient.getLogs()[0].method).toBe("post");
});
it("should pass space, name to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});

describe("updateThread", () => {
const params = {
id: THREAD_ID,
Expand Down

0 comments on commit e08575a

Please sign in to comment.