Skip to content

Commit c8bd788

Browse files
authored
feat: schedule.searchAvailableTimes (#36)
1 parent 47afcdb commit c8bd788

File tree

3 files changed

+107
-2
lines changed

3 files changed

+107
-2
lines changed

docs/schedule.md

+30
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [addEvent](#addevent)
66
- [updateEvent](#updateevent)
77
- [deleteEvent](#deleteevent)
8+
- [searchAvailableTimes](#searchavailabletimes)
89

910
## Overview
1011

@@ -198,3 +199,32 @@ See the example response in the `Reference`.
198199
#### Reference
199200

200201
- https://developer.cybozu.io/hc/ja/articles/360000393866
202+
203+
### searchAvailableTimes
204+
205+
Search available times of users, organizations and facilities.
206+
207+
#### Parameters
208+
209+
| Name | Type | Required | Description |
210+
| ----------------------- | :--------------: | :-------------------------: | ------------------------------------------------------------------------------------------ |
211+
| timeRanges | Array\<Object\> | Yes | The list of search time ranges. |
212+
| timeRanges[].start | String | Yes | The start datetime of the time range. The format is RFC3339. (e.g. `2020-01-01T00:00:00Z`) |
213+
| timeRanges[].end | String | Yes | The end datetime of the time range. The format is RFC3339. (e.g. `2020-01-01T00:00:00Z`) |
214+
| timeInterval | number | Yes | The search time interval. |
215+
| attendees | Array\<Object\> | Conditionally<br />Required | The list of attendees. Required if `facilities` is not specified. |
216+
| attendees[].type | String | Yes | The attendee type. Possible values are `ORGANIZATION`, `USER`. |
217+
| attendees[].id | Number or String | Conditionally<br />Required | The ID of the attendee. Required if `attendees[].code` is not specified. |
218+
| attendees[].code | String | Conditionally<br />Required | The code of the attendee. Required if `attendees[].id` is not specified. |
219+
| facilities | Array\<Object\> | Conditionally<br />Required | The list of facilities. Required if `attendees` is not specified. |
220+
| facilities[].id | Number or String | Conditionally<br />Required | The ID of the facility. Required if `facilities[].code` is not specified. |
221+
| facilities[].code | String | Conditionally<br />Required | The code of the facility. Required if `facilities[].id` is not specified. |
222+
| facilitySearchCondition | String | | The facility search condition. Possible values are `AND`, `OR`. |
223+
224+
#### Returns
225+
226+
See the example response in the `Reference`.
227+
228+
#### Reference
229+
230+
- https://developer.cybozu.io/hc/ja/articles/360018417771#step1

src/client/ScheduleClient.ts

+39-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class ScheduleClient {
9595
watchers?: Array<{
9696
type: "ORGANIZATION" | "USER" | "ROLE";
9797
id?: string | number;
98-
code?: string | number;
98+
code?: string;
9999
}>;
100100
additionalItems?: {
101101
item?: {
@@ -147,7 +147,7 @@ export class ScheduleClient {
147147
watchers?: Array<{
148148
type: "ORGANIZATION" | "USER" | "ROLE";
149149
id?: string | number;
150-
code?: string | number;
150+
code?: string;
151151
}>;
152152
additionalItems?: {
153153
item?: {
@@ -166,4 +166,41 @@ export class ScheduleClient {
166166
const path = buildPath({ endpointName: `schedule/events/${id}` });
167167
await this.client.delete(path, {});
168168
}
169+
170+
public searchAvailableTimes(params: {
171+
timeRanges: Array<{
172+
start: string;
173+
end: string;
174+
}>;
175+
timeInterval: number;
176+
attendees?: Array<{
177+
type: "ORGANIZATION" | "USER";
178+
id?: string | number;
179+
code?: string;
180+
}>;
181+
facilities?: Array<{
182+
id?: string | number;
183+
code?: string;
184+
}>;
185+
facilitySearchCondition?: "AND" | "OR";
186+
}): Promise<{
187+
availableTimes: Array<{
188+
start: {
189+
dateTime: string;
190+
timeZone: string;
191+
};
192+
end: {
193+
dateTime: string;
194+
timeZone: string;
195+
};
196+
facility: {
197+
id: string;
198+
code: string;
199+
name: string;
200+
};
201+
}>;
202+
}> {
203+
const path = buildPath({ endpointName: "schedule/searchAvailableTimes" });
204+
return this.client.post(path, params);
205+
}
169206
}

src/client/__tests__/ScheduleClient.test.ts

+38
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,42 @@ describe("ScheduleClient", () => {
246246
expect(mockClient.getLogs()[0].params).toEqual({});
247247
});
248248
});
249+
250+
describe("searchAvailableTimes", () => {
251+
const params = {
252+
timeRanges: [
253+
{
254+
start: "2020-07-01T14:00:00+09:00",
255+
end: "2020-07-01T15:00:00+09:00",
256+
},
257+
],
258+
timeInterval: 30,
259+
attendees: [
260+
{
261+
type: "USER" as const,
262+
id: 6,
263+
},
264+
],
265+
facilities: [
266+
{
267+
id: 1,
268+
},
269+
],
270+
facilitySearchCondition: "OR" as const,
271+
};
272+
beforeEach(async () => {
273+
await scheduleClient.searchAvailableTimes(params);
274+
});
275+
it("should pass the path to the http client", () => {
276+
expect(mockClient.getLogs()[0].path).toBe(
277+
"/api/v1/schedule/searchAvailableTimes"
278+
);
279+
});
280+
it("should send a post request", () => {
281+
expect(mockClient.getLogs()[0].method).toBe("post");
282+
});
283+
it("should pass params as a param to the http client", () => {
284+
expect(mockClient.getLogs()[0].params).toEqual(params);
285+
});
286+
});
249287
});

0 commit comments

Comments
 (0)