Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat: added api call for getting breakrules #141

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
24 changes: 24 additions & 0 deletions src/clockodo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
29 changes: 27 additions & 2 deletions src/clockodo.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -857,6 +861,18 @@ export class Clockodo {
): Promise<HolidayscarryRowReturnType> {
return this.api.get("/holidayscarry", params);
}

async getWorktimeRegulations(
params?: Params
): Promise<WorktimeRegulationsReturnType> {
return this.api.get("/v2/worktimeRegulations", params);
}

async getWorktimeBreakRules(
params?: Params
): Promise<WorktimeBreakRulesReturnType> {
return this.api.get("/v2/worktimeBreakRules", params);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workTimeBreakRules

}
}

export type AbsenceReturnType = { absence: Absence };
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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<WorktimeRegulation>;
};

export type WorktimeBreakRulesReturnType = {
worktimeBreakRules: Array<WorktimeBreakRule>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data

};
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
24 changes: 24 additions & 0 deletions src/models/worktimeBreakRule.ts
Original file line number Diff line number Diff line change
@@ -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;
};
};
4 changes: 2 additions & 2 deletions src/models/worktimeRegulation.mocks.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
33 changes: 12 additions & 21 deletions src/models/worktimeRegulation.ts
Original file line number Diff line number Diff line change
@@ -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) */
Expand All @@ -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<BreakRule>;
/** 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<Omit<WorktimeBreakRule, "id" | "worktimeRegulationsId">>;
};