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

feat: added overtime reductions #136

Closed
wants to merge 11 commits into from
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
18 changes: 15 additions & 3 deletions src/clockodo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,13 +653,25 @@ describe("Clockodo (instance)", () => {
});
});

describe("getOvertimecarry()", () => {
it("correctly builds getOvertimecarry() request", async () => {
describe("getOvertimeCarryovers()", () => {
it("correctly builds getOvertimeCarryovers() request", async () => {
const nockScope = nock(CLOCKODO_API)
.get("/overtimecarry?users_id=17&year=2028")
.reply(200, {});

await clockodo.getOvertimecarry({ usersId: 17, year: 2028 });
await clockodo.getOvertimeCarryovers({ usersId: 17, year: 2028 });

nockScope.done();
});
});

describe("getOvertimeReductions()", () => {
it("correctly builds getOvertimeReductions() request", async () => {
const nockScope = nock(CLOCKODO_API)
.get("/overtimeReductions?users_id=17&year=2028")
.reply(200, {});

await clockodo.getOvertimeReductions({ usersId: 17, year: 2028 });

nockScope.done();
});
Expand Down
29 changes: 22 additions & 7 deletions src/clockodo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ import {
WorkTimeChangeRequestStatus,
WorkTimeDay,
} from "./models/workTimes.js";
import { OvertimecarryRow } from "./models/overtimecarry.js";
import { OvertimeCarryover } from "./models/overtimeCarryover.js";
import { HolidaysquotaRow } from "./models/holidaysquota.js";
import { HolidayscarryRow } from "./models/holidayscarry.js";
import { OvertimeReduction } from "./models/overtimeReduction.js";

export class Clockodo {
api: Api;
Expand Down Expand Up @@ -840,9 +841,9 @@ export class Clockodo {
);
}

async getOvertimecarry(
params?: Params<OvertimecarryRowParams>
): Promise<OvertimecarryRowReturnType> {
async getOvertimeCarryovers(
params?: Params<OvertimeCarryoversParams>
): Promise<OvertimeCarryoverReturnType> {
return this.api.get("/overtimecarry", params);
}

Expand All @@ -857,6 +858,12 @@ export class Clockodo {
): Promise<HolidayscarryRowReturnType> {
return this.api.get("/holidayscarry", params);
}

async getOvertimeReductions(
params?: Params<OvertimeReductionsParams>
): Promise<OvertimeReductionsReturnType> {
return this.api.get("/overtimeReductions", params);
dsumer marked this conversation as resolved.
Show resolved Hide resolved
}
}

export type AbsenceReturnType = { absence: Absence };
Expand Down Expand Up @@ -1163,16 +1170,24 @@ export type AddWorkTimesChangeRequestReturnType =
replacedChangeRequest: null;
};

export type OvertimecarryRowReturnType = {
overtimecarry: Array<OvertimecarryRow>;
export type OvertimeCarryoverReturnType = {
overtimecarry: Array<OvertimeCarryover>;
};
export type OvertimecarryRowParams = {
export type OvertimeCarryoversParams = {
/** The user ID by which the overtime carry rows should be filtered */
usersId?: number;
/** The year to which the data should be restricted to */
year?: number;
};

export type OvertimeReductionsReturnType = {
overtimeReductions: Array<OvertimeReduction>;
};
export type OvertimeReductionsParams = {
/** The user ID by which the overtime reduced rows should be filtered */
usersId?: number;
};

export type HolidaysquotaRowReturnType = {
holidaysquota: Array<HolidaysquotaRow>;
};
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export * from "./models/holidaysquota.js";
export * from "./models/lumpsumService.js";
export * from "./models/nonbusinessDay.js";
export * from "./models/nonbusinessGroup.js";
export * from "./models/overtimecarry.js";
export * from "./models/overtimeCarryover.js";
export * from "./models/overtimeReduction.js";
export * from "./models/project.js";
export * from "./models/service.js";
export * from "./models/targethours.js";
Expand Down
3 changes: 2 additions & 1 deletion src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export * from "./models/holidaysquota.mocks.js";
export * from "./models/lumpsumService.mocks.js";
export * from "./models/service.mocks.js";
export * from "./models/nonbusinessDay.mocks.js";
export * from "./models/overtimecarry.mocks.js";
export * from "./models/overtimeCarryover.mocks.js";
export * from "./models/overtimeReduction.mocks.js";
export * from "./models/project.mocks.js";
// export * from "./models/service.mocks.js";
export * from "./models/targethours.mocks.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { faker } from "@faker-js/faker";
import { OvertimecarryRow } from "./overtimecarry.js";
import { OvertimeCarryover } from "./overtimeCarryover.js";

type Options = {
count?: number;
hoursMinMax?: [number, number];
yearMinMax?: [number, number];
};

export const createOvertimecarryMocks = ({
export const createOvertimeCarryoverMocks = ({
count = 1,
hoursMinMax = [0, 100],
yearMinMax = [1900, 2024],
}: Options = {}) => {
return Array.from({ length: count }, (): OvertimecarryRow => {
return Array.from({ length: count }, (): OvertimeCarryover => {
return {
usersId: 0,
year: faker.datatype.number({ min: yearMinMax[0], max: yearMinMax[1] }),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type OvertimecarryRow = {
export type OvertimeCarryover = {
/** The related employee's ID */
usersId: number;
/**
Expand Down
28 changes: 28 additions & 0 deletions src/models/overtimeReduction.mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { faker } from "@faker-js/faker";
import { OvertimeReduction } from "./overtimeReduction.js";
import { isoDateFromDateTime } from "../lib/dateTime.js";

type Options = {
count?: number;
hoursMinMax?: [number, number];
};

export const createOvertimeReductionMocks = ({
count = 1,
hoursMinMax = [0, 100],
}: Options = {}) => {
return Array.from({ length: count }, (_, index): OvertimeReduction => {
return {
id: index,
usersId: 0,
usersIdAdded: 1,
dateAdded: isoDateFromDateTime(faker.date.past()),
note: faker.datatype.boolean() ? faker.lorem.sentences(2) : null,
hours: faker.datatype.number({
min: hoursMinMax[0],
max: hoursMinMax[1],
}),
createdAfterEndOfMonth: faker.datatype.boolean(),
};
});
};
17 changes: 17 additions & 0 deletions src/models/overtimeReduction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { IsoDate } from "./dateTime.js";

export type OvertimeReduction = {
/** The ID of the overtime reduction */
id: number;
/** The related employee's ID */
usersId: number;
/** The user who added the overtime reduction */
usersIdAdded: number;
/** The date when the overtime reduction was added */
dateAdded: IsoDate;
/** Number of hours */
hours: number;
note: string | null;
// TODO: will probably be renamed
createdAfterEndOfMonth: boolean;
};