Skip to content

Commit

Permalink
Merge branch 'main' into add-surcharge-model
Browse files Browse the repository at this point in the history
  • Loading branch information
dsumer committed Oct 24, 2023
2 parents abf0980 + 23e5960 commit cdb9e39
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 121 deletions.
198 changes: 91 additions & 107 deletions CHANGELOG.md

Large diffs are not rendered by default.

34 changes: 29 additions & 5 deletions src/clockodo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,34 @@ describe("Clockodo (instance)", () => {
});
});

describe("getHolidaysquota()", () => {
it("correctly builds getHolidaysquota() request", async () => {
const nockScope = nock(CLOCKODO_API)
.get("/holidaysquota?users_id=17")
.reply(200, {});

await clockodo.getHolidaysquota({ usersId: 17 });

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

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

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

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

describe("getSurchargeModel()", () => {
it("correctly builds getSurchargeModel() request", async () => {
const nockScope = nock(CLOCKODO_API)
.get("/v2/surcharges/7")
.get("/v2/surchargeModels/7")
.reply(200, {});

await clockodo.getSurchargeModel({ id: 7 });
Expand All @@ -608,7 +632,7 @@ describe("Clockodo (instance)", () => {
describe("getSurchargeModels()", () => {
it("correctly builds getSurchargeModels() request", async () => {
const nockScope = nock(CLOCKODO_API)
.get("/v2/surcharges")
.get("/v2/surchargeModels")
.reply(200, {});

await clockodo.getSurchargeModels();
Expand Down Expand Up @@ -904,7 +928,7 @@ describe("Clockodo (instance)", () => {
};

const nockScope = nock(CLOCKODO_API)
.post("/v2/surcharges", expectedParameters)
.post("/v2/surchargeModels", expectedParameters)
.reply(200, {});

await clockodo.addSurchargeModel({
Expand Down Expand Up @@ -1080,7 +1104,7 @@ describe("Clockodo (instance)", () => {
};

const nockScope = nock(CLOCKODO_API)
.put("/v2/surcharges/365", mapRequestBody(entry))
.put("/v2/surchargeModels/365", mapRequestBody(entry))
.reply(200, {});

await clockodo.editSurchargeModel(entry);
Expand Down Expand Up @@ -1218,7 +1242,7 @@ describe("Clockodo (instance)", () => {
describe("deleteSurchargeModel()", () => {
it("correctly builds deleteSurchargeModel() request", async () => {
const nockScope = nock(CLOCKODO_API)
.delete("/v2/surcharges/31")
.delete("/v2/surchargeModels/31")
.reply(200, {});

await clockodo.deleteSurchargeModel({ id: 31 });
Expand Down
48 changes: 41 additions & 7 deletions src/clockodo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import {
WorkTimeChangeRequestStatus,
WorkTimeDay,
} from "./models/workTimes.js";
import { HolidaysquotaRow } from "./models/holidaysquota.js";
import { HolidayscarryRow } from "./models/holidayscarry.js";
import { SurchargeModel } from "./models/surchargeModel.js";

export class Clockodo {
Expand Down Expand Up @@ -337,13 +339,13 @@ export class Clockodo {

const { id, ...remainingParams } = params;

return this.api.get("/v2/surcharges/" + id, remainingParams);
return this.api.get("/v2/surchargeModels/" + id, remainingParams);
}

async getSurchargeModels(
params?: Params
): Promise<SurchargeModelsReturnType> {
return this.api.get("/v2/surcharges", params);
return this.api.get("/v2/surchargeModels", params);
}

async getUserReport<
Expand Down Expand Up @@ -473,7 +475,7 @@ export class Clockodo {
): Promise<SurchargeModelReturnType> {
REQUIRED.checkRequired(params, REQUIRED.ADD_SURCHARGE_MODEL);

return this.api.post("/v2/surcharges", params);
return this.api.post("/v2/surchargeModels", params);
}

async startClock(
Expand Down Expand Up @@ -593,7 +595,7 @@ export class Clockodo {

const { id } = params;

return this.api.put("/v2/surcharges/" + id, params);
return this.api.put("/v2/surchargeModels/" + id, params);
}

async deactivateCustomer(
Expand Down Expand Up @@ -645,7 +647,7 @@ export class Clockodo {

const { id } = params;

return this.api.delete("/v2/surcharges/" + id);
return this.api.delete("/v2/surchargeModels/" + id);
}

async deleteAbsence(
Expand Down Expand Up @@ -816,6 +818,18 @@ export class Clockodo {
remainingParams
);
}

async getHolidaysquota(
params?: Params<HolidaysquotaRowParams>
): Promise<HolidaysquotaRowReturnType> {
return this.api.get("/holidaysquota", params);
}

async getHolidayscarry(
params?: Params<HolidayscarryRowParams>
): Promise<HolidayscarryRowReturnType> {
return this.api.get("/holidayscarry", params);
}
}

export type AbsenceReturnType = { absence: Absence };
Expand Down Expand Up @@ -861,8 +875,10 @@ export type LumpsumServicesReturnType = {
};
export type UserReturnType = { user: User };
export type UsersReturnType = { users: Array<User> };
export type SurchargeModelReturnType = { surcharge: SurchargeModel };
export type SurchargeModelsReturnType = { surcharges: Array<SurchargeModel> };
export type SurchargeModelReturnType = { surchargeModel: SurchargeModel };
export type SurchargeModelsReturnType = {
surchargeModels: Array<SurchargeModel>;
};
export type EntryReturnType = { entry: Entry };
export type AddEntryReturnType = { entry: Entry; stopped?: Entry };
export type EditEntryReturnType = {
Expand Down Expand Up @@ -1106,3 +1122,21 @@ export type AddWorkTimesChangeRequestReturnType =
**/
replacedChangeRequest: null;
};

export type HolidaysquotaRowReturnType = {
holidaysquota: Array<HolidaysquotaRow>;
};
export type HolidaysquotaRowParams = {
/** The user ID by which the holidays quota rows should be filtered */
usersId?: number;
};

export type HolidayscarryRowReturnType = {
holidayscarry: Array<HolidayscarryRow>;
};
export type HolidayscarryRowParams = {
/** The user ID by which the holidays carry rows should be filtered */
usersId?: number;
/** The year to which the data should be restricted to */
year?: number;
};
5 changes: 3 additions & 2 deletions src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ export * from "./models/absence.mocks.js";
export * from "./models/customer.mocks.js";
export * from "./models/entry.mocks.js";
// export * from "./models/entryGroup.mocks.js";
// export * from "./models/holidayscarry.mocks.js";
// export * from "./models/holidaysquota.mocks.js";
export * from "./models/holidayscarry.mocks.js";
export * from "./models/holidaysquota.mocks.js";
export * from "./models/lumpsumService.mocks.js";
export * from "./models/nonbusinessDay.mocks.js";
export * from "./models/project.mocks.js";
// export * from "./models/service.mocks.js";
export * from "./models/surchargeModel.mocks.js";
export * from "./models/targethours.mocks.js";
export * from "./models/team.mocks.js";
export * from "./models/user.mocks.js";
// export * from "./models/userReport.mocks.js";
export * from "./models/worktimeRegulation.mocks.js";
Expand Down
5 changes: 5 additions & 0 deletions src/models/__snapshots__/workTimes.mocks.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Array [
"type": 1,
},
],
"createdAt": "2020-03-24T04:00:00Z",
"date": "2020-03-24",
"id": 0,
"status": 1,
Expand All @@ -43,6 +44,7 @@ Array [
"type": 2,
},
],
"createdAt": "2020-04-14T04:00:00Z",
"date": "2020-04-14",
"id": 1,
"status": 1,
Expand All @@ -56,6 +58,7 @@ Array [
"type": 2,
},
],
"createdAt": "2020-06-05T04:00:00Z",
"date": "2020-06-05",
"id": 2,
"status": 1,
Expand All @@ -79,6 +82,7 @@ Array [
"type": 1,
},
],
"createdAt": "2020-09-11T04:00:00Z",
"date": "2020-09-11",
"id": 3,
"status": 1,
Expand All @@ -97,6 +101,7 @@ Array [
"type": 1,
},
],
"createdAt": "2020-09-17T04:00:00Z",
"date": "2020-09-17",
"id": 4,
"status": 1,
Expand Down
21 changes: 21 additions & 0 deletions src/models/holidayscarry.mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { faker } from "@faker-js/faker";
import { HolidayscarryRow } from "./holidayscarry.js";

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

export const createHolidayscarryMocks = ({
count = 1,
yearMinMax = [1900, 2024],
}: Options = {}) => {
return Array.from({ length: count }, (): HolidayscarryRow => {
return {
usersId: 0,
year: faker.datatype.number({ min: yearMinMax[0], max: yearMinMax[1] }),
note: faker.datatype.boolean() ? faker.lorem.sentences(2) : null,
count: faker.datatype.number({ min: 0, max: 100 }),
};
});
};
5 changes: 5 additions & 0 deletions src/models/holidayscarry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export type HolidayscarryRow = {
/** The related employee's ID */
usersId: number;
/**
* Year for which the holiday carryover applies
*/
year: number;
/** Day count */
count: number;
note: string | null;
};
35 changes: 35 additions & 0 deletions src/models/holidaysquota.mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { faker } from "@faker-js/faker";
import { HolidaysquotaRow } from "./holidaysquota.js";

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

export const createHolidaysquotaMocks = ({
count = 1,
yearSinceMinMax = [2020, 2021],
yearUntilMinMax = [2021, 2022],
}: Options = {}) => {
return Array.from({ length: count }, (_, index): HolidaysquotaRow => {
const id = index;

return {
id,
usersId: 0,
yearSince: faker.datatype.number({
min: yearSinceMinMax[0],
max: yearSinceMinMax[1],
}),
yearUntil: faker.datatype.boolean()
? faker.datatype.number({
min: yearUntilMinMax[0],
max: yearUntilMinMax[1],
})
: null,
note: faker.datatype.boolean() ? faker.lorem.sentences(2) : null,
count: faker.datatype.number({ min: 0, max: 100 }),
};
});
};
9 changes: 9 additions & 0 deletions src/models/holidaysquota.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
export type HolidaysquotaRow = {
/** The ID of the holiday quota settings */
id: number;
/** The related employee's ID */
usersId: number;
/**
* Year from which on the holiday quota setting apply
*/
yearSince: number;
/**
* Year until which the holiday quota setting apply
*/
yearUntil: number | null;
/** Count of holidays */
count: number;
note: string | null;
};
Expand Down
10 changes: 10 additions & 0 deletions src/models/team.mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { faker } from "@faker-js/faker";
import { Team } from "./team.js";

export const createTeamMocks = ({ count = 1 }: { count?: number }) =>
Array.from({ length: count }, (_, index): Team => {
return {
id: index,
name: faker.name.jobArea() + " Team",
};
});
6 changes: 6 additions & 0 deletions src/models/workTimes.mocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { faker } from "@faker-js/faker";
import {
isoDateFromDateTime,
isoUtcDateTimeFromDateTime,
isoUtcDateTimeFromTimestamp,
} from "../lib/dateTime.js";
import {
Expand Down Expand Up @@ -105,22 +106,26 @@ const createChangeRequest = ({
date,
id,
status = WorkTimeChangeRequestStatus.Requested,
createdAt,
}: {
date: Date;
id: number;
status?: WorkTimeChangeRequestStatus;
createdAt?: Date;
}): WorkTimeChangeRequest => {
const changes = generateChangeRequestChanges({
count: faker.datatype.number({ min: 1, max: 4 }),
date,
});
const isoDate = isoDateFromDateTime(date);
const isoCreatedAt = isoUtcDateTimeFromDateTime(createdAt ?? new Date());

return {
id,
date: isoDate,
usersId: 0,
changes,
createdAt: isoCreatedAt,
...(status === WorkTimeChangeRequestStatus.Declined
? {
status: WorkTimeChangeRequestStatus.Declined,
Expand Down Expand Up @@ -152,6 +157,7 @@ export const createWorkTimeChangeRequestMocks = ({
return createChangeRequest({
date,
id,
createdAt: date,
});
});
};
1 change: 1 addition & 0 deletions src/models/workTimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type WorkTimeChangeRequest = {
id: number;
date: IsoDate;
usersId: number;
createdAt: IsoUtcDateTime;
changes: Array<WorkTimeChangeRequestInterval>;
} & (
| {
Expand Down

0 comments on commit cdb9e39

Please sign in to comment.