diff --git a/docs/schedule.md b/docs/schedule.md index ff96465..c7756bc 100644 --- a/docs/schedule.md +++ b/docs/schedule.md @@ -5,6 +5,7 @@ - [addEvent](#addevent) - [updateEvent](#updateevent) - [deleteEvent](#deleteevent) +- [searchAvailableTimes](#searchavailabletimes) ## Overview @@ -198,3 +199,32 @@ See the example response in the `Reference`. #### Reference - https://developer.cybozu.io/hc/ja/articles/360000393866 + +### searchAvailableTimes + +Search available times of users, organizations and facilities. + +#### Parameters + +| Name | Type | Required | Description | +| ----------------------- | :--------------: | :-------------------------: | ------------------------------------------------------------------------------------------ | +| timeRanges | Array\ | Yes | The list of search time ranges. | +| timeRanges[].start | String | Yes | The start datetime of the time range. The format is RFC3339. (e.g. `2020-01-01T00:00:00Z`) | +| timeRanges[].end | String | Yes | The end datetime of the time range. The format is RFC3339. (e.g. `2020-01-01T00:00:00Z`) | +| timeInterval | number | Yes | The search time interval. | +| attendees | Array\ | Conditionally
Required | The list of attendees. Required if `facilities` is not specified. | +| attendees[].type | String | Yes | The attendee type. Possible values are `ORGANIZATION`, `USER`. | +| attendees[].id | Number or String | Conditionally
Required | The ID of the attendee. Required if `attendees[].code` is not specified. | +| attendees[].code | String | Conditionally
Required | The code of the attendee. Required if `attendees[].id` is not specified. | +| facilities | Array\ | Conditionally
Required | The list of facilities. Required if `attendees` is not specified. | +| facilities[].id | Number or String | Conditionally
Required | The ID of the facility. Required if `facilities[].code` is not specified. | +| facilities[].code | String | Conditionally
Required | The code of the facility. Required if `facilities[].id` is not specified. | +| facilitySearchCondition | String | | The facility search condition. Possible values are `AND`, `OR`. | + +#### Returns + +See the example response in the `Reference`. + +#### Reference + +- https://developer.cybozu.io/hc/ja/articles/360018417771#step1 diff --git a/src/client/ScheduleClient.ts b/src/client/ScheduleClient.ts index d765a72..b991c1a 100644 --- a/src/client/ScheduleClient.ts +++ b/src/client/ScheduleClient.ts @@ -95,7 +95,7 @@ export class ScheduleClient { watchers?: Array<{ type: "ORGANIZATION" | "USER" | "ROLE"; id?: string | number; - code?: string | number; + code?: string; }>; additionalItems?: { item?: { @@ -147,7 +147,7 @@ export class ScheduleClient { watchers?: Array<{ type: "ORGANIZATION" | "USER" | "ROLE"; id?: string | number; - code?: string | number; + code?: string; }>; additionalItems?: { item?: { @@ -166,4 +166,41 @@ export class ScheduleClient { const path = buildPath({ endpointName: `schedule/events/${id}` }); await this.client.delete(path, {}); } + + public searchAvailableTimes(params: { + timeRanges: Array<{ + start: string; + end: string; + }>; + timeInterval: number; + attendees?: Array<{ + type: "ORGANIZATION" | "USER"; + id?: string | number; + code?: string; + }>; + facilities?: Array<{ + id?: string | number; + code?: string; + }>; + facilitySearchCondition?: "AND" | "OR"; + }): Promise<{ + availableTimes: Array<{ + start: { + dateTime: string; + timeZone: string; + }; + end: { + dateTime: string; + timeZone: string; + }; + facility: { + id: string; + code: string; + name: string; + }; + }>; + }> { + const path = buildPath({ endpointName: "schedule/searchAvailableTimes" }); + return this.client.post(path, params); + } } diff --git a/src/client/__tests__/ScheduleClient.test.ts b/src/client/__tests__/ScheduleClient.test.ts index 5c2c0b5..1c50e3f 100644 --- a/src/client/__tests__/ScheduleClient.test.ts +++ b/src/client/__tests__/ScheduleClient.test.ts @@ -246,4 +246,42 @@ describe("ScheduleClient", () => { expect(mockClient.getLogs()[0].params).toEqual({}); }); }); + + describe("searchAvailableTimes", () => { + const params = { + timeRanges: [ + { + start: "2020-07-01T14:00:00+09:00", + end: "2020-07-01T15:00:00+09:00", + }, + ], + timeInterval: 30, + attendees: [ + { + type: "USER" as const, + id: 6, + }, + ], + facilities: [ + { + id: 1, + }, + ], + facilitySearchCondition: "OR" as const, + }; + beforeEach(async () => { + await scheduleClient.searchAvailableTimes(params); + }); + it("should pass the path to the http client", () => { + expect(mockClient.getLogs()[0].path).toBe( + "/api/v1/schedule/searchAvailableTimes" + ); + }); + it("should send a post request", () => { + expect(mockClient.getLogs()[0].method).toBe("post"); + }); + it("should pass params as a param to the http client", () => { + expect(mockClient.getLogs()[0].params).toEqual(params); + }); + }); });