Skip to content

Commit

Permalink
feat: schedule.updateEvent (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
miyajan authored Jul 5, 2020
1 parent 6b30524 commit e5c6c1b
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 2 deletions.
57 changes: 55 additions & 2 deletions docs/schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [getEvent](#getevent)
- [getEvents](#getevents)
- [addEvent](#addevent)
- [updateEvent](#updateevent)

## Overview

Expand Down Expand Up @@ -83,10 +84,10 @@ Add a regular or periodic event. A repeating or tentative event cannot be added
| subject | String | | The event subject. |
| notes | String | | The event memo. |
| start | Object | Yes | An object containing data of the start datetime. |
| start.dateTime | String | Yes | The start datetime of the event. |
| start.dateTime | String | Yes | The start datetime of the event. The format is RFC3339. (e.g. `2020-01-01T00:00:00Z`) |
| start.timeZone | String | Yes | The timezone of the start datetime. |
| 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`. |
| end.dateTime | String | Yes | The end datetime of the event. |
| end.dateTime | String | Yes | The end datetime of the event. The format is RFC3339. (e.g. `2020-01-01T00:00:00Z`) |
| end.timeZone | String | Yes | The timezone of the end datetime. |
| isAllDay | Boolean | | It indicates whether the event is all-day. |
| 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. |
Expand Down Expand Up @@ -125,3 +126,55 @@ See the example response in the `Reference`.
#### Reference

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

### updateEvent

Update an event by specifying the event ID. A tentative event cannot be updated by this API.

#### Parameters

| Name | Type | Required | Description |
| -------------------------- | :--------------: | :-------------------------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| eventMenu | String | | The event menu. An empty string is taken as the default setting ("-----"). |
| subject | String | | The event subject. |
| notes | String | | The event memo. |
| start | Object | Yes | An object containing data of the start datetime. |
| start.dateTime | String | Yes | The start datetime of the event. The format is RFC3339. (e.g. `2020-01-01T00:00:00Z`) |
| start.timeZone | String | Yes | The timezone of the start datetime. |
| 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`. |
| end.dateTime | String | Yes | The end datetime of the event. The format is RFC3339. (e.g. `2020-01-01T00:00:00Z`) |
| end.timeZone | String | Yes | The timezone of the end datetime. |
| isAllDay | Boolean | | It indicates whether the event is all-day. |
| 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. |
| 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. |
| facilityUsingPurpose | String | Conditionally<br />Required | The purpose of the use of the facility. Required if "Facility usage request" is enabled. |
| companyInfo | Object | | An object containing data of the company. |
| companyInfo.name | String | | The company name. |
| companyInfo.zipCode | String | | The zip code of the company. |
| companyInfo.address | String | | The company address. |
| companyInfo.route | String | | The route to the company. |
| companyInfo.routeTime | String | | The time of the route. |
| companyInfo.routeFare | String | | The fare of the route. |
| companyInfo.phone | String | | The phone number of the company. |
| visibilityType | String | | The visibility type. Possible values are `PUBLIC`, `PRIVATE`, `SET_PRIVATE_WATCHERS`. |
| useAttendanceCheck | Boolean | | It indicates whether "Request responses" of attendees is enabled. |
| watchers | Array\<Object\> | Conditionally<br />Required | The list of private watchers. Required if `visibilityType` is `SET_PRIVATE_WATCHERS`. |
| watchers[].type | String | Yes | The type of the watcher. Possible values are `ORGANIZATION`, `USER`, `ROLE`. |
| watchers[].id | Number or String | Conditionally<br />Required | The ID of the watcher. Required if `watchers[].code` is not specified. |
| watchers[].code | String | Conditionally<br />Required | The code of the watcher. Required if `watchers[].id` is not specified. |
| additionalItems | Object | | An object containing data of additional items. |
| additionalItems.item.value | String | | The value of the item. |

#### Returns

See the example response in the `Reference`.

#### Reference

- https://developer.cybozu.io/hc/ja/articles/360000495746#step1
54 changes: 54 additions & 0 deletions src/client/ScheduleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,58 @@ export class ScheduleClient {
const path = buildPath({ endpointName: "schedule/events" });
return this.client.post(path, params);
}

public updateEvent(params: {
id: EventID;
event: {
eventMenu?: string;
subject?: string;
notes?: string;
start: {
dateTime: string;
timeZone: string;
};
end?: {
dateTime: string;
timeZone: string;
};
isAllDay?: boolean;
isStartOnly?: boolean;
attendees?: Array<{
type: "ORGANIZATION" | "USER";
id?: string | number;
code?: string;
}>;
facilities?: Array<{
id?: string | number;
code?: string;
}>;
facilityUsingPurpose?: string;
companyInfo?: {
name?: string;
zipCode?: string;
address?: string;
route?: string;
routeTime?: string;
routeFare?: string;
phone?: string;
};
visibilityType?: "PUBLIC" | "PRIVATE" | "SET_PRIVATE_WATCHERS";
useAttendanceCheck?: boolean;
watchers?: Array<{
type: "ORGANIZATION" | "USER" | "ROLE";
id?: string | number;
code?: string | number;
}>;
additionalItems?: {
item?: {
value?: string;
};
};
};
}): Promise<Event> {
const { id, event } = params;
const path = buildPath({ endpointName: `schedule/events/${id}` });
return this.client.patch(path, event);
}
}
67 changes: 67 additions & 0 deletions src/client/__tests__/ScheduleClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,71 @@ describe("ScheduleClient", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});

describe("updateEvent", () => {
const params = {
id: "1",
event: {
eventMenu: "MTG",
subject: "Weekly conference",
notes: "This is notes.",
start: {
dateTime: "2020-07-01T14:00:00+09:00",
timeZone: "Asia/Tokyo",
},
end: {
dateTime: "2020-07-01T15:00:00+09:00",
timeZone: "Asia/Tokyo",
},
isAllDay: false,
isStartOnly: false,
attendees: [
{
type: "USER" as const,
id: 1,
},
],
facilities: [
{
id: 1,
},
],
facilityUsingPurpose: "Because of the explanation of a new plan",
companyInfo: {
name: "Cybozu, Inc.",
zipCode: "103-xxxx",
address: "2-7-1, Nihombashi, Chuo-ku, Tokyo",
route: "Nihombashi Sta. - Ginza Line - Shibuya Sta.",
routeTime: "18",
routeFare: "195",
phone: "03-4306-xxxx",
},
visibilityType: "PUBLIC" as const,
useAttendanceCheck: false,
watchers: [
{
type: "USER" as const,
id: 2,
},
],
additionalItems: {
item: {
value: "hoge",
},
},
},
};
beforeEach(async () => {
await scheduleClient.updateEvent(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/api/v1/schedule/events/1");
});
it("should send a patch request", () => {
expect(mockClient.getLogs()[0].method).toBe("patch");
});
it("should pass params.event as a param to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual(params.event);
});
});
});

0 comments on commit e5c6c1b

Please sign in to comment.