UNPKG

node-calendly

Version:
137 lines 5.82 kB
"use strict"; /****************************************** * Author : Dr. Sebastian Herden * Created On : Fri Sep 16 2022 * File : EventTypes.ts *******************************************/ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const CalendlyApiEndpointWithOrganization_1 = __importDefault(require("./CalendlyApiEndpointWithOrganization")); const EventType_1 = __importDefault(require("./types/EventType")); /** * The event types endpoint. * @export default * @class EventTypes * @extends {CalendlyApiEndpointWithOrganization} * @see https://developer.calendly.com/api-docs/25a4ece03c1bc-list-user-s-event-types */ class EventTypes extends CalendlyApiEndpointWithOrganization_1.default { constructor(ACCESS_TOKEN, organizationProvider, meProvider, params) { super(ACCESS_TOKEN, organizationProvider, params); this.meProvider = meProvider; } /** * Returns all Event Types associated with a specified User. If user is not specified, the current user is used. * @param params * @returns {Promise<PaginationResponse<EventType>>} A paginated list of Event Types. */ listUsersEventTypes(params) { return __awaiter(this, void 0, void 0, function* () { if (!params.user) { params.user = yield this.meProvider.getMe(); // request default me } return yield this.listEventTypes(params); }); } /** * Returns all Event Types associated with a specified Organization. If organization is not specified, the current organization is used. * @param params The request parameters. * @returns {Promise<PaginationResponse<EventType>>} A paginated list of Event Types. */ listOrganisationEventTypes(params) { return __awaiter(this, void 0, void 0, function* () { if (!params.organization) { params.organization = yield this.organizationProvider.getOrganizationUri(); // request default organization } return yield this.listEventTypes(params); }); } /** * Returns information about a specified Event Type. * @param param The uuid of the event type. * @returns {Promise<EventType>} The event type. */ getEventType({ uuid }) { return __awaiter(this, void 0, void 0, function* () { const url = `https://api.calendly.com/event_types/${uuid}`; const response = yield this.fetchGet(url); return EventType_1.default.fromJson(response.resource); }); } // TODO: has errors /** * Returns a list of available times for an event type within a specified date range. * Date range can be no greater than 1 week (7 days). * * NOTE: * * This endpoint does not support traditional keyset pagination. * @param params The request parameters. * @returns {Promise<EventTypeAvailableTimeResponse>} The available times. * @note This endpoint does not support traditional keyset pagination. * @todo has errors */ listEventAvailableTimes(params) { return __awaiter(this, void 0, void 0, function* () { const queryParams = this.getEventTypeAvailableTimeRequestParams(params); const url = `https://api.calendly.com/event_type_available_times?${queryParams}`; return yield this.fetchGet(url); }); } listEventTypes(params) { return __awaiter(this, void 0, void 0, function* () { const queryParams = this.getListEventTypesRequestParams(params); const url = `https://api.calendly.com/event_types?${queryParams}`; return yield this.fetchGet(url); }); } getListEventTypesRequestParams(params) { const queryParams = []; if (params.organization) { queryParams.push(`organization=${params.organization}`); } if (params.user) { queryParams.push(`user=${params.user}`); } if (params.active) { queryParams.push(`active=${params.active}`); } if (params.count) { queryParams.push(`count=${params.count}`); } if (params.page_token) { queryParams.push(`page_token=${params.page_token}`); } if (params.sort) { queryParams.push(`sort=${params.sort}`); } return queryParams.join('&'); } getEventTypeAvailableTimeRequestParams(params) { const queryParams = []; if (params.end_time) { queryParams.push(`end_time=${params.end_time.toISOString()}`); } if (params.start_time) { queryParams.push(`start_time=${params.start_time.toISOString()}`); } if (params.event_type) { queryParams.push(`event_type=${params.event_type}`); } return queryParams.join('&'); } } exports.default = EventTypes; //# sourceMappingURL=EventTypes.js.map