diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d25503d..0b374f18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,14 @@ # [22.2.0](https://github.com/peerigon/clockodo/compare/v22.1.0...v22.2.0) (2023-11-06) - ### Features -* Use v3 API for services and lumpsum services ([#131](https://github.com/peerigon/clockodo/issues/131)) ([1a8ba9d](https://github.com/peerigon/clockodo/commit/1a8ba9d1fad6a6251a1116a39bfd1886a048bce1)) +- Use v3 API for services and lumpsum services ([#131](https://github.com/peerigon/clockodo/issues/131)) ([1a8ba9d](https://github.com/peerigon/clockodo/commit/1a8ba9d1fad6a6251a1116a39bfd1886a048bce1)) # [22.1.0](https://github.com/peerigon/clockodo/compare/v22.0.0...v22.1.0) (2023-11-06) - ### Features -* Add testData property to targethoursRow ([#140](https://github.com/peerigon/clockodo/issues/140)) ([9c2e511](https://github.com/peerigon/clockodo/commit/9c2e5119004eeb89c95b53e42815e95fbf5e071e)) +- Add testData property to targethoursRow ([#140](https://github.com/peerigon/clockodo/issues/140)) ([9c2e511](https://github.com/peerigon/clockodo/commit/9c2e5119004eeb89c95b53e42815e95fbf5e071e)) # [22.0.0](https://github.com/peerigon/clockodo/compare/v21.15.0...v22.0.0) (2023-10-24) diff --git a/src/clockodo.test.ts b/src/clockodo.test.ts index 65431515..7f25aea1 100644 --- a/src/clockodo.test.ts +++ b/src/clockodo.test.ts @@ -688,6 +688,30 @@ describe("Clockodo (instance)", () => { nockScope.done(); }); }); + + describe("getWorktimeRegulations()", () => { + it("correctly builds getWorktimeRegulations() request", async () => { + const nockScope = nock(CLOCKODO_API) + .get("/v2/worktimeRegulations") + .reply(200, {}); + + await clockodo.getWorktimeRegulations(); + + nockScope.done(); + }); + }); + + describe("getWorktimeBreakRules()", () => { + it("correctly builds getWorktimeBreakRules() request", async () => { + const nockScope = nock(CLOCKODO_API) + .get("/v2/worktimeBreakRules") + .reply(200, {}); + + await clockodo.getWorktimeBreakRules(); + + nockScope.done(); + }); + }); }); describe("POST", () => { diff --git a/src/clockodo.ts b/src/clockodo.ts index 1f3acaa6..57c82d9e 100644 --- a/src/clockodo.ts +++ b/src/clockodo.ts @@ -1,5 +1,8 @@ import { NonbusinessGroup } from "./models/nonbusinessGroup.js"; -import { WorktimeRegulation } from "./models/worktimeRegulation.js"; +import { + WorktimeRegulation, + WorktimeRegulationWithRules, +} from "./models/worktimeRegulation.js"; import { Absence } from "./models/absence.js"; import { Customer } from "./models/customer.js"; import { @@ -44,6 +47,7 @@ import { import { OvertimecarryRow } from "./models/overtimecarry.js"; import { HolidaysquotaRow } from "./models/holidaysquota.js"; import { HolidayscarryRow } from "./models/holidayscarry.js"; +import { WorktimeBreakRule } from "./models/worktimeBreakRule.js"; export class Clockodo { api: Api; @@ -857,6 +861,18 @@ export class Clockodo { ): Promise { return this.api.get("/holidayscarry", params); } + + async getWorktimeRegulations( + params?: Params + ): Promise { + return this.api.get("/v2/worktimeRegulations", params); + } + + async getWorktimeBreakRules( + params?: Params + ): Promise { + return this.api.get("/v2/worktimeBreakRules", params); + } } export type AbsenceReturnType = { absence: Absence }; @@ -1054,7 +1070,7 @@ export type NonbusinessDaysReturnType = { export type AggregatesUsersMeReturnType = { user: User; company: Company; - worktimeRegulation: WorktimeRegulation; + worktimeRegulation: WorktimeRegulationWithRules; }; export type ClockReturnType = { /** The currently running entry */ @@ -1190,3 +1206,12 @@ export type HolidayscarryRowParams = { /** The year to which the data should be restricted to */ year?: number; }; + +/** The user ID by which the overtime carry rows should be filtered */ +export type WorktimeRegulationsReturnType = { + worktimeRegulations: Array; +}; + +export type WorktimeBreakRulesReturnType = { + worktimeBreakRules: Array; +}; diff --git a/src/index.ts b/src/index.ts index 8ef76776..b711627a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ export * from "./models/absence.js"; export * from "./models/access.js"; +export * from "./models/worktimeBreakRule.js"; export * from "./models/company.js"; export * from "./models/customer.js"; export * from "./models/dateTime.js"; diff --git a/src/models/worktimeBreakRule.ts b/src/models/worktimeBreakRule.ts new file mode 100644 index 00000000..03e02fd7 --- /dev/null +++ b/src/models/worktimeBreakRule.ts @@ -0,0 +1,24 @@ +export type WorktimeBreakRule = { + /** ID of the break rule */ + id: number; + /** ID of the corresponding worktime regulation */ + worktimeRegulationsId: number; + /** 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: { + /** Only one break */ + "1"?: number; + /** At least one break */ + "1+"?: number; + /** Two breaks */ + "2"?: number; + /** Three breaks */ + "3"?: number; + }; +}; diff --git a/src/models/worktimeRegulation.mocks.ts b/src/models/worktimeRegulation.mocks.ts index fedb29aa..19d459e2 100644 --- a/src/models/worktimeRegulation.mocks.ts +++ b/src/models/worktimeRegulation.mocks.ts @@ -1,8 +1,8 @@ -import { WorktimeRegulation } from "./worktimeRegulation.js"; +import { WorktimeRegulationWithRules } from "./worktimeRegulation.js"; export const worktimeRegulationCountryPresets: Record< "Germany" | "Austria" | "Switzerland" | "Netherlands" | "Greece" | "France", - WorktimeRegulation + WorktimeRegulationWithRules > = { Germany: { id: -1, diff --git a/src/models/worktimeRegulation.ts b/src/models/worktimeRegulation.ts index 8c7b4c64..830a20fa 100644 --- a/src/models/worktimeRegulation.ts +++ b/src/models/worktimeRegulation.ts @@ -1,6 +1,10 @@ +import { WorktimeBreakRule } from "./worktimeBreakRule.js"; + export type WorktimeRegulation = { /** ID of the worktime regulation */ id: number; + /** The name of the worktime regulation */ + name: string; /** Do mandatory breaks count as worktime? */ addToWorktime: boolean; /** Maximum allowed worktime per week (in hours) */ @@ -9,27 +13,14 @@ export type WorktimeRegulation = { dailyMax: number | null; /** Maximum allowed worktime without a break (in hours) */ intervalMax: number | null; - /** Contains objects of the type "breakrule" */ - rules: Array; + /** Indicated if a worktimeregulation is a preset */ + preset: boolean; }; -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: { - /** Only one break */ - "1"?: number; - /** At least one break */ - "1+"?: number; - /** Two breaks */ - "2"?: number; - /** Three breaks */ - "3"?: number; - }; +export type WorktimeRegulationWithRules = Omit< + WorktimeRegulation, + "name" | "preset" +> & { + /** Contains objects of the type "worktimeBreakRules" */ + rules: Array>; };