Skip to content

Commit 6b30524

Browse files
authored
feat: schedule.addEvent (#32)
1 parent 0580974 commit 6b30524

13 files changed

+402
-113
lines changed

docs/schedule.md

+58-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- [getEvent](#getevent)
44
- [getEvents](#getevents)
5+
- [addEvent](#addevent)
56

67
## Overview
78

@@ -56,7 +57,7 @@ Get events by specifying conditions.
5657
| orderBy.order | String | Yes | The sort order. Possible values are: `asc`, `desc`. If nothing is specified, it will default to `asc`. |
5758
| rangeStart | String | | The start datetime for the search. The format is RFC3339. (e.g. `2020-01-01T00:00:00Z`)<br />If `rangeEnd` is specified, `rangeStart` must be before the `rangeEnd`. |
5859
| rangeEnd | String | | The end datetime for the search. The format is RFC3339. (e.g. `2020-01-01T00:00:00Z`)<br />If `rangeStart` is specified, `rangeEnd` must be later than `rangeStart`. |
59-
| target | Number or String | Conditionally<br />Required | The ID of an user or an organization or a facility. Required if `targetType` is specified. If nothing is specified, it will default to the login user ID. |
60+
| target | Number or String | Conditionally<br />Required | The ID of the target. Required if `targetType` is specified. If nothing is specified, it will default to the login user ID. |
6061
| targetType | String | Conditionally<br />Required | The target type. Possible values are: `user`, `organization`, `facility`. Required if `target` is specified. If nothing is specified, it will default to `user`. |
6162
| keyword | String | Conditionally<br />Required | The search keyword. The keyword is searched for subject, company information, notes and comments. Required if `excludeFromSearch` is specified. |
6263
| excludeFromSearch | Array\<String\> | | The specified elements are excluded from the keyword search. Possible values are: `subject`, `company`, `notes`, `comments`. |
@@ -68,3 +69,59 @@ See the example response in the `Reference`.
6869
#### Reference
6970

7071
- https://developer.cybozu.io/hc/ja/articles/360000440583#step2
72+
73+
### addEvent
74+
75+
Add a regular or periodic event. A repeating or tentative event cannot be added by this API.
76+
77+
#### Parameters
78+
79+
| Name | Type | Required | Description |
80+
| -------------------------- | :--------------: | :-------------------------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
81+
| eventType | String | Yes | The event type. Possible values are: `REGULAR`, `ALL_DAY`. |
82+
| eventMenu | String | | The event menu. An empty string is taken as the default setting ("-----"). |
83+
| subject | String | | The event subject. |
84+
| notes | String | | The event memo. |
85+
| start | Object | Yes | An object containing data of the start datetime. |
86+
| start.dateTime | String | Yes | The start datetime of the event. |
87+
| start.timeZone | String | Yes | The timezone of the start datetime. |
88+
| end | Object | Conditionally<br />Required | An object containing data of the end datetime. Required if `isStartOnly` is false, `facilities` is specified, or `eventType` is `ALL_DAY`. |
89+
| end.dateTime | String | Yes | The end datetime of the event. |
90+
| end.timeZone | String | Yes | The timezone of the end datetime. |
91+
| isAllDay | Boolean | | It indicates whether the event is all-day. |
92+
| isStartOnly | Boolean | Conditionally<br />Required | It indicates whether the event has only the start datetime. If nothing is specified, it will default to `false`. It must be specified as `true` if `end` is not specified. |
93+
| attendees | Array\<Object\> | Conditionally<br />Required | The list of attendees. Required if `facilities` is not specified. |
94+
| attendees[].type | String | Yes | The attendee type. Possible values are `ORGANIZATION`, `USER`. |
95+
| attendees[].id | Number or String | Conditionally<br />Required | The ID of the attendee. Required if `attendees[].code` is not specified. |
96+
| attendees[].code | String | Conditionally<br />Required | The code of the attendee. Required if `attendees[].id` is not specified. |
97+
| facilities | Array\<Object\> | Conditionally<br />Required | The list of facilities. Required if `attendees` is not specified. |
98+
| facilities[].id | Number or String | Conditionally<br />Required | The ID of the facility. Required if `facilities[].code` is not specified. |
99+
| facilities[].code | String | Conditionally<br />Required | The code of the facility. Required if `facilities[].id` is not specified. |
100+
| facilityUsingPurpose | String | Conditionally<br />Required | The purpose of the use of the facility. Required if "Facility usage request" is enabled. |
101+
| companyInfo | Object | | An object containing data of the company. |
102+
| companyInfo.name | String | | The company name. |
103+
| companyInfo.zipCode | String | | The zip code of the company. |
104+
| companyInfo.address | String | | The company address. |
105+
| companyInfo.route | String | | The route to the company. |
106+
| companyInfo.routeTime | String | | The time of the route. |
107+
| companyInfo.routeFare | String | | The fare of the route. |
108+
| companyInfo.phone | String | | The phone number of the company. |
109+
| attachments | Array\<Object\> | | The list of attachments. |
110+
| attachments[].name | String | | The name of the attachment. |
111+
| attachments[].content | String | | The content of the attachment. It must be base64 string. |
112+
| visibilityType | String | | The visibility type. Possible values are `PUBLIC`, `PRIVATE`, `SET_PRIVATE_WATCHERS`. |
113+
| useAttendanceCheck | Boolean | | It indicates whether "Request responses" of attendees is enabled. |
114+
| watchers | Array\<Object\> | Conditionally<br />Required | The list of private watchers. Required if `visibilityType` is `SET_PRIVATE_WATCHERS`. |
115+
| watchers[].type | String | Yes | The type of the watcher. Possible values are `ORGANIZATION`, `USER`, `ROLE`. |
116+
| watchers[].id | Number or String | Conditionally<br />Required | The ID of the watcher. Required if `watchers[].code` is not specified. |
117+
| watchers[].code | String | Conditionally<br />Required | The code of the watcher. Required if `watchers[].id` is not specified. |
118+
| additionalItems | Object | | An object containing data of additional items. |
119+
| additionalItems.item.value | String | | The value of the item. |
120+
121+
#### Returns
122+
123+
See the example response in the `Reference`.
124+
125+
#### Reference
126+
127+
- https://developer.cybozu.io/hc/ja/articles/360000425163#step1

package-lock.json

+8-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
"dependencies": {
8181
"axios": "^0.19.2",
8282
"core-js": "^3.6.5",
83-
"form-data": "^3.0.0",
8483
"js-base64": "^2.6.2",
8584
"qs": "^6.9.4"
8685
}

src/GaroonRequestConfigBuilder.ts

+4-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import FormData from "form-data";
21
import qs from "qs";
32
import { Base64 } from "js-base64";
43

@@ -12,7 +11,7 @@ import {
1211
import { BasicAuth, DiscriminatedAuth } from "./GaroonRestAPIClient";
1312
import { platformDeps } from "./platform/";
1413

15-
type Data = Params | FormData;
14+
type Data = Params;
1615

1716
type GaroonAuthHeader =
1817
| {
@@ -108,26 +107,16 @@ export class GaroonRequestConfigBuilder implements RequestConfigBuilder {
108107
};
109108
}
110109
case "post": {
111-
if (params instanceof FormData) {
112-
const formData = await this.buildData(params);
113-
return {
114-
...requestConfig,
115-
headers:
116-
// NOTE: formData.getHeaders does not exist in a browser environment.
117-
typeof formData.getHeaders === "function"
118-
? { ...this.headers, ...formData.getHeaders() }
119-
: this.headers,
120-
data: formData,
121-
};
122-
}
123110
return {
124111
...requestConfig,
112+
headers: { ...this.headers, "Content-Type": "application/json" },
125113
data: await this.buildData(params),
126114
};
127115
}
128-
case "put": {
116+
case "patch": {
129117
return {
130118
...requestConfig,
119+
headers: { ...this.headers, "Content-Type": "application/json" },
131120
data: await this.buildData(params),
132121
};
133122
}
@@ -154,10 +143,6 @@ export class GaroonRequestConfigBuilder implements RequestConfigBuilder {
154143
private async buildData<T extends Data>(params: T): Promise<T> {
155144
if (this.auth.type === "session") {
156145
const requestToken = await this.getRequestToken();
157-
if (params instanceof FormData) {
158-
params.append("__REQUEST_TOKEN__", requestToken);
159-
return params;
160-
}
161146
return {
162147
__REQUEST_TOKEN__: requestToken,
163148
...params,

0 commit comments

Comments
 (0)