Skip to content

Commit

Permalink
feat: schedule.getFacilityGroups (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
miyajan authored Jul 9, 2020
1 parent 63ed823 commit a679bc7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
22 changes: 21 additions & 1 deletion docs/schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [deleteEvent](#deleteevent)
- [searchAvailableTimes](#searchavailabletimes)
- [getFacilities](#getfacilities)
- [getFacilityGroups](#getfacilitygroups)

## Overview

Expand Down Expand Up @@ -238,7 +239,7 @@ Get facilities by specifying conditions.

| Name | Type | Required | Description |
| ------ | :----: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------ |
| 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`. |
| 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`. |
| name | String | | The facility name. |

Expand All @@ -249,3 +250,22 @@ See the example response in the `Reference`.
#### Reference

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

### getFacilityGroups

Get facility groups by specifying conditions.

#### Parameters

| Name | Type | Required | Description |
| ------ | :----: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------ |
| limit | Number | | The number of facility groups 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#step1
24 changes: 22 additions & 2 deletions src/client/ScheduleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class ScheduleClient {
return this.client.post(path, params);
}

public getFacilities(params: {
public getFacilities(params?: {
limit?: number;
offset?: number;
name?: string;
Expand All @@ -219,6 +219,26 @@ export class ScheduleClient {
hasNext: boolean;
}> {
const path = buildPath({ endpointName: "schedule/facilities" });
return this.client.get(path, params);
return this.client.get(path, params ?? {});
}

public getFacilityGroups(params?: {
limit?: number;
offset?: number;
}): Promise<{
facilityGroups: Array<{
id: string;
name: string;
code: string;
notes: string;
parentFacilityGroup: string | null;
childFacilityGroups: Array<{
id: string;
}>;
}>;
hasNext: boolean;
}> {
const path = buildPath({ endpointName: "schedule/facilityGroups" });
return this.client.get(path, params ?? {});
}
}
21 changes: 21 additions & 0 deletions src/client/__tests__/ScheduleClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,25 @@ describe("ScheduleClient", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});

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

0 comments on commit a679bc7

Please sign in to comment.