Skip to content

Commit

Permalink
feat: schedule.searchAvailableTimes (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
miyajan authored Jul 7, 2020
1 parent 47afcdb commit c8bd788
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
30 changes: 30 additions & 0 deletions docs/schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [addEvent](#addevent)
- [updateEvent](#updateevent)
- [deleteEvent](#deleteevent)
- [searchAvailableTimes](#searchavailabletimes)

## Overview

Expand Down Expand Up @@ -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\<Object\> | 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\<Object\> | Conditionally<br />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<br />Required | The ID of the attendee. Required if `attendees[].code` is not specified. |
| attendees[].code | String | Conditionally<br />Required | The code of the attendee. Required if `attendees[].id` is not specified. |
| facilities | Array\<Object\> | Conditionally<br />Required | The list of facilities. Required if `attendees` is not specified. |
| facilities[].id | Number or String | Conditionally<br />Required | The ID of the facility. Required if `facilities[].code` is not specified. |
| facilities[].code | String | Conditionally<br />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
41 changes: 39 additions & 2 deletions src/client/ScheduleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class ScheduleClient {
watchers?: Array<{
type: "ORGANIZATION" | "USER" | "ROLE";
id?: string | number;
code?: string | number;
code?: string;
}>;
additionalItems?: {
item?: {
Expand Down Expand Up @@ -147,7 +147,7 @@ export class ScheduleClient {
watchers?: Array<{
type: "ORGANIZATION" | "USER" | "ROLE";
id?: string | number;
code?: string | number;
code?: string;
}>;
additionalItems?: {
item?: {
Expand All @@ -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);
}
}
38 changes: 38 additions & 0 deletions src/client/__tests__/ScheduleClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit c8bd788

Please sign in to comment.