From 744ac7a7b9559f9789cbb514d768a901d4fdc12e Mon Sep 17 00:00:00 2001 From: Aminreza Badeleh Mansoori <48173745+aminmansoori@users.noreply.github.com> Date: Mon, 9 Dec 2024 08:48:13 +0100 Subject: [PATCH] userEvents endpoint is added (#893) --- src/index.ts | 4 ++++ src/userEvents/index.ts | 17 +++++++++++++++++ src/userEvents/types.ts | 4 ++++ src/utils/response/apiResponse.ts | 3 +++ 4 files changed, 28 insertions(+) create mode 100644 src/userEvents/index.ts create mode 100644 src/userEvents/types.ts diff --git a/src/index.ts b/src/index.ts index fae55d46..a8c69ed1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -72,6 +72,7 @@ import { TimesheetActionLogsEndpoint } from './timesheetActionLogs'; import { HolidayAdjustmentEndpoint } from './holidayAdjustment'; import { HourTypesEndpoint } from './hourTypes'; import { FetchDataEndpoint } from './fetchData'; +import { UserEventsEndpoint } from './userEvents'; export { AbsenceBan } from './absenceBans/types'; export { AbsenceDay } from './absenceDays/types'; @@ -195,6 +196,7 @@ export { PublicHolidays, PublicHolidaysCreate, PublicHolidaysUpdate } from './pu export { TimesheetActionLogs } from './timesheetActionLogs/types'; export { HolidayAdjustmentAdd, HolidayAdjustmentRemove } from './holidayAdjustment/types'; export { HourType } from './hourTypes/types'; +export { UserEvent } from './userEvents/types'; const DEFAULT_HOST = 'go.timetac.com'; @@ -273,6 +275,7 @@ export default class Api { public holidayAdjustment: HolidayAdjustmentEndpoint; public hourTypes: HourTypesEndpoint; public fetchData: FetchDataEndpoint; + public userEvents: UserEventsEndpoint; constructor(config: ApiConfig) { this.config = new ConfigProvider({ @@ -357,6 +360,7 @@ export default class Api { this.integrationsToCategories = new IntegrationsToCategoriesEndpoint(this.config); this.publicHolidays = new PublicHolidaysEndpoint(this.config); this.fetchData = new FetchDataEndpoint(this.config); + this.userEvents = new UserEventsEndpoint(this.config); this.holidayAdjustment = new HolidayAdjustmentEndpoint(this.config); this.hourTypes = new HourTypesEndpoint(this.config); diff --git a/src/userEvents/index.ts b/src/userEvents/index.ts new file mode 100644 index 00000000..57675f9e --- /dev/null +++ b/src/userEvents/index.ts @@ -0,0 +1,17 @@ +import BaseApi from '../baseApi'; +import { Entity } from '../utils/response/apiResponse'; +import { RequestParams } from '../utils/params/requestParams'; +import { Required, requiredSingle } from '../utils/response/responseHandlers'; +import { UserEvent } from './types'; + +const resourceName = 'userEvents'; +type ResourceName = typeof resourceName; + +export class UserEventsEndpoint extends BaseApi { + public readonly resourceName = resourceName; + + public create(data: UserEvent, params?: RequestParams>): Required { + const response = this._post('create', data, params); + return requiredSingle(response); + } +} diff --git a/src/userEvents/types.ts b/src/userEvents/types.ts new file mode 100644 index 00000000..c9e49c12 --- /dev/null +++ b/src/userEvents/types.ts @@ -0,0 +1,4 @@ +export type UserEvent = { + event_name: string; + user_id: number; +}; diff --git a/src/utils/response/apiResponse.ts b/src/utils/response/apiResponse.ts index f1fd3a0e..7877e98f 100644 --- a/src/utils/response/apiResponse.ts +++ b/src/utils/response/apiResponse.ts @@ -65,6 +65,7 @@ import { Integration } from '../../integrations/types'; import { IntegrationToCategory } from '../../integrationsToCategories/types'; import { PublicHolidays } from '../../publicHolidays/types'; import { HourType } from '../../hourTypes/types'; +import { UserEvent } from '../../userEvents/types'; // Because types cannot be iterated at runtime, we add the keys of Resources here as a value // Below we add conditional types that don't compile if this array and Resources go out of sync export const resourceNameArray = [ @@ -137,6 +138,7 @@ export const resourceNameArray = [ 'integrationsToCategories', 'holidayAdjustment', 'hourTypes', + 'userEvents', ] as const; export interface Resources { @@ -226,6 +228,7 @@ export interface Resources { publicHolidays: PublicHolidays; holidayAdjustment: TimesheetActionLogs; hourTypes: HourType; + userEvents: UserEvent; } // These conditional types ensure that the resourceNameArray and the Resources type are in sync