Skip to content

Commit

Permalink
userEvents endpoint is added (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminmansoori authored Dec 9, 2024
1 parent d7015d1 commit 744ac7a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions src/userEvents/index.ts
Original file line number Diff line number Diff line change
@@ -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<ResourceName> {
public readonly resourceName = resourceName;

public create(data: UserEvent, params?: RequestParams<Entity<ResourceName>>): Required<ResourceName> {
const response = this._post<ResourceName>('create', data, params);
return requiredSingle(response);
}
}
4 changes: 4 additions & 0 deletions src/userEvents/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type UserEvent = {
event_name: string;
user_id: number;
};
3 changes: 3 additions & 0 deletions src/utils/response/apiResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -137,6 +138,7 @@ export const resourceNameArray = [
'integrationsToCategories',
'holidayAdjustment',
'hourTypes',
'userEvents',
] as const;

export interface Resources {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 744ac7a

Please sign in to comment.