Skip to content

Commit

Permalink
feat: schedule.getFacilitiesByFacilityGroupID (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
miyajan authored Jul 11, 2020
1 parent a679bc7 commit fa99c55
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
23 changes: 22 additions & 1 deletion docs/schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [searchAvailableTimes](#searchavailabletimes)
- [getFacilities](#getfacilities)
- [getFacilityGroups](#getfacilitygroups)
- [getFacilitiesByFacilityGroupID](#getfacilitiesbyfacilitygroupid)

## Overview

Expand Down Expand Up @@ -213,7 +214,7 @@ Search available times of users, organizations and facilities.
| 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. |
| 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. |
Expand Down Expand Up @@ -269,3 +270,23 @@ See the example response in the `Reference`.
#### Reference

- https://developer.cybozu.io/hc/ja/articles/360017481472#step1

### getFacilitiesByFacilityGroupID

Get facilities belonging to the specified facility group.

#### Parameters

| Name | Type | Required | Description |
| ------ | :--------------: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------ |
| id | Number or String | Yes | The facility group ID. |
| limit | Number | | The number of facilities to retrieve.<br />Must be between `1` and `1000`.<br />If nothing is specified, it will default to `100`. |
| offset | Number | | The number of retrievals that will be skipped.<br />Must be between `0` and `2147483647`. If nothing is specified, it will default to `0`. |

#### Returns

See the example response in the `Reference`.

#### Reference

- https://developer.cybozu.io/hc/ja/articles/360017481472#step2
20 changes: 20 additions & 0 deletions src/client/ScheduleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,24 @@ export class ScheduleClient {
const path = buildPath({ endpointName: "schedule/facilityGroups" });
return this.client.get(path, params ?? {});
}

public getFacilitiesByFacilityGroupID(params: {
id: string | number;
limit?: number;
offset?: number;
}): Promise<{
facilities: Array<{
id: string;
name: string;
code: string;
notes: string;
facilityGroup: string;
}>;
}> {
const { id, ...rest } = params;
const path = buildPath({
endpointName: `schedule/facilityGroups/${id}/facilities`,
});
return this.client.get(path, rest as Record<string, unknown>);
}
}
25 changes: 25 additions & 0 deletions src/client/__tests__/ScheduleClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,29 @@ describe("ScheduleClient", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});

describe("getFacilitiesByFacilityGroupID", () => {
const params = {
id: 1,
limit: 100,
offset: 0,
};
beforeEach(async () => {
await scheduleClient.getFacilitiesByFacilityGroupID(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe(
"/api/v1/schedule/facilityGroups/1/facilities"
);
});
it("should send a get request", () => {
expect(mockClient.getLogs()[0].method).toBe("get");
});
it("should pass limit and offset as a param to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual({
limit: 100,
offset: 0,
});
});
});
});

0 comments on commit fa99c55

Please sign in to comment.