From 3c22c75576521e68c27a75f7c4eb58f0fbac26e5 Mon Sep 17 00:00:00 2001 From: miyajan Date: Sun, 5 Jul 2020 18:19:12 +0900 Subject: [PATCH] feat: schedule.updateEvent --- docs/schedule.md | 57 +++++++++++++++++- src/client/ScheduleClient.ts | 54 +++++++++++++++++ src/client/__tests__/ScheduleClient.test.ts | 67 +++++++++++++++++++++ 3 files changed, 176 insertions(+), 2 deletions(-) diff --git a/docs/schedule.md b/docs/schedule.md index 9e647aa..7276ae3 100644 --- a/docs/schedule.md +++ b/docs/schedule.md @@ -3,6 +3,7 @@ - [getEvent](#getevent) - [getEvents](#getevents) - [addEvent](#addevent) +- [updateEvent](#updateevent) ## Overview @@ -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
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
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. | @@ -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
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
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\ | Conditionally
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
Required | The ID of the attendee. Required if `attendees[].code` is not specified. | +| attendees[].code | String | Conditionally
Required | The code of the attendee. Required if `attendees[].id` is not specified. | +| facilities | Array\ | Conditionally
Required | The list of facilities. Required if `attendees` is not specified. | +| facilities[].id | Number or String | Conditionally
Required | The ID of the facility. Required if `facilities[].code` is not specified. | +| facilities[].code | String | Conditionally
Required | The code of the facility. Required if `facilities[].id` is not specified. | +| facilityUsingPurpose | String | Conditionally
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\ | Conditionally
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
Required | The ID of the watcher. Required if `watchers[].code` is not specified. | +| watchers[].code | String | Conditionally
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 diff --git a/src/client/ScheduleClient.ts b/src/client/ScheduleClient.ts index f41115a..28228c6 100644 --- a/src/client/ScheduleClient.ts +++ b/src/client/ScheduleClient.ts @@ -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 { + const { id, event } = params; + const path = buildPath({ endpointName: `schedule/events/${id}` }); + return this.client.patch(path, event); + } } diff --git a/src/client/__tests__/ScheduleClient.test.ts b/src/client/__tests__/ScheduleClient.test.ts index 2191a65..a6ed65c 100644 --- a/src/client/__tests__/ScheduleClient.test.ts +++ b/src/client/__tests__/ScheduleClient.test.ts @@ -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); + }); + }); });