Skip to content

Commit

Permalink
feat: Add getAggregatesUsersMe()
Browse files Browse the repository at this point in the history
With this resource you can read user and company seetings for the logged in user. Editing is currently not possible.
See https://www.clockodo.com/en/api/aggregates/users/me/
  • Loading branch information
jhnns committed Nov 1, 2021
1 parent 3b063ab commit c6385e1
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,18 @@ await clockodo.getUserReports({ year: 2017, type: 1 });

---

### [getAggregatesUsersMe()](https://www.clockodo.com/en/api/aggregates/users/me/)

With this resource you can read user and company seetings for the logged in user. Editing is currently not possible.

#### Example:

```js
await clockodo.getAggregatesUsersMe();
```

---

## Post Methods

### addAbsence()
Expand Down
13 changes: 13 additions & 0 deletions src/clockodo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import snakecaseKeys from "snakecase-keys";
import { WorktimeRegulation } from "./models/worktimeRegulation";
import { Absence } from "./models/absence.js";
import { Customer } from "./models/customer.js";
import {
Expand All @@ -19,6 +20,7 @@ import { User } from "./models/user.js";
import { UserReport } from "./models/userReport.js";
import { Api, Config, Filter, Paging } from "./lib/api.js";
import * as REQUIRED from "./lib/requiredParams.js";
import { Company } from "./models/company.js";

type Params<
RequiredParams extends Record<string, unknown> = Record<string, unknown>
Expand Down Expand Up @@ -231,6 +233,12 @@ export class Clockodo {
return this.api.get("/userreports", params);
}

async getAggregatesUsersMe(
params?: Params
): Promise<AggregatesUsersMeReturnType> {
return this.api.get("/v2/aggregates/users/me", params);
}

async addAbsence(
params: Params<Pick<Absence, typeof REQUIRED.ADD_ABSENCE[number]>>
): Promise<AbsenceReturnType> {
Expand Down Expand Up @@ -514,6 +522,11 @@ export type DeleteEntryGroupsReturnType =
| { success: true; deletedEntries: number };
export type UserReportReturnType = { userreport: UserReport };
export type UserReportsReturnType = { userreports: Array<UserReport> };
export type AggregatesUsersMeReturnType = {
user: User;
company: Company;
worktimeRegulation: WorktimeRegulation;
};
export type ClockReturnType = {
running: null | TimeEntry;
currentTime: string;
Expand Down
11 changes: 11 additions & 0 deletions src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,15 @@ const config: Config = {
).toMatchObject(expectedKeys.concat([]).sort());
});
});

describe("getAggregatesUsersMe()", () => {
it("returns expected data format", async () => {
const { user, company, worktimeRegulation } =
await clockodo.getAggregatesUsersMe();

expect(user).toHaveProperty("id");
expect(company).toHaveProperty("id");
expect(worktimeRegulation).toHaveProperty("id");
});
});
});
65 changes: 65 additions & 0 deletions src/models/company.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
export type Company = {
/** ID of the company */
id: number;
/** Name of the company */
name: string;
/** Default timezone of the company */
timezoneDefault: string;
/** Currency of the company */
currency: string;
/** Are time and lump sum entries with multiline descriptions allowed? */
allowEntriesTextMultiline: boolean;
/** Can time and lump sum entries be directly assigned to customers (or only to projects)? */
allowEntriesForCustomers: boolean;
/** Does the duration of a time entry have to be equal to the difference between start and end? */
forceLinkedEntryTimes: boolean;
/** ID of the default customer */
defaultCustomersId: number | null;
/** ID of the default service */
defaultServicesId: number | null;
/** Is the absence module active for the company? */
moduleAbsence: boolean;
/** Is the target hours module active for the company? */
moduleTargetHours: boolean;
/** Is the user report module active for the company? */
moduleUserReports: boolean;
/** ID of the default nonbusiness group */
nonbusinessGroupDefault: number | null;
/** ID of the default worktime regulation */
worktimeRegulationDefault: number | null;
/**
* Date from which worktime regulations are evaluated for the company in YYYY-MM-DD format
*/
worktimeEvaluateRegulationsSince: string | null;
/** Is missing break time subtracted from the tracked work time? */
worktimeForceBreaks: boolean;
/** Number of days in the default holiday quota of the company */
holidaysCountDefault: number;
/**
* Are absences handled by reducing the target hours for the day?
* If not, time is added to the worktime account for absences
*/
absenceReducesTargetHours: boolean;
/** Default value for automatically compensated overtime per day (in minutes) */
compensateDayDefault: number;
/** Default value for automatically compensated overtime per month (in hours) */
compensateMonthDefault: number;
targetHoursDefault: {
/** Default value for targethours on mondays */
monday: number;
/** Default value for targethours on tuesdays */
tuesday: number;
/** Default value for targethours on wednesdays */
wednesday: number;
/** Default value for targethours on thursdays */
thursday: number;
/** Default value for targethours on fridays */
friday: number;
/** Default value for targethours on saturdays */
saturday: number;
/** Default value for targethours on sundays */
sunday: number;
};
/** Has the registration process been completed? */
onboardingComplete: boolean;
};
27 changes: 27 additions & 0 deletions src/models/worktimeRegulation.ts
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
export const NO_WORKTIME_REGULATIONS_ID = 0 as const;

export type WorktimeRegulation = {
/** ID of the worktime regulation */
id: number;
/** Do mandatory breaks count as worktime? */
addToWorktime: boolean;
/** Maximum allowed worktime per week (in hours) */
weeklyMax: number;
/** Maximum allowed worktime per day (in hours) */
dailyMax: number;
/** Maximum allowed worktime without a break (in hours) */
intervalMax: number;
/** Contains objects of the type "breakrule" */
rules: Array<BreakRule>;
};

export type BreakRule = {
/** Daily worktime (in hours), above which the rule applies */
worktime: number;
/** Required total break time */
breakSum: number;
/**
* Contains the break splitting options as key-value pair.
* The key represents the number of breaks into which the required time may be split, the value contains the minimum length of a single break (in minutes)
**/
splitting: Record<number, number>;
};

0 comments on commit c6385e1

Please sign in to comment.