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: Add surcharge model and api request handlers #124

Merged
merged 24 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
12 changes: 4 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
# [23.0.0](https://github.com/peerigon/clockodo/compare/v22.2.0...v23.0.0) (2023-11-21)


### Bug Fixes

* Rename HolidaysQuota and HolidaysCarryover ([#145](https://github.com/peerigon/clockodo/issues/145)) ([16543bf](https://github.com/peerigon/clockodo/commit/16543bffc60339daf05f1ad1f46efd2a4ef30207))

- Rename HolidaysQuota and HolidaysCarryover ([#145](https://github.com/peerigon/clockodo/issues/145)) ([16543bf](https://github.com/peerigon/clockodo/commit/16543bffc60339daf05f1ad1f46efd2a4ef30207))

### BREAKING CHANGES

* We've renamed `HolidayscarryRow` to `HolidaysCarryover` and `HolidaysquotaRow` to `HolidaysQuota` and adjusted all method names accordingly to make the naming more consistent.
- We've renamed `HolidayscarryRow` to `HolidaysCarryover` and `HolidaysquotaRow` to `HolidaysQuota` and adjusted all method names accordingly to make the naming more consistent.

# [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
73 changes: 73 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("getSurchargeModel()", () => {
it("correctly builds getSurchargeModel() request", async () => {
const nockScope = nock(CLOCKODO_API)
.get("/v2/surchargeModels/7")
.reply(200, {});

await clockodo.getSurchargeModel({ id: 7 });

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

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

await clockodo.getSurchargeModels();

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

describe("POST", () => {
Expand Down Expand Up @@ -987,6 +1011,26 @@ describe("Clockodo (instance)", () => {
nockScope.done();
});
});

describe("addSurchargeModel()", () => {
it("correctly builds addSurchargeModel() request", async () => {
const expectedParameters = {
name: "Weyland-Yutani",
accumulation: true,
};

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

await clockodo.addSurchargeModel({
name: "Weyland-Yutani",
accumulation: true,
});

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

describe("PUT", () => {
Expand Down Expand Up @@ -1160,6 +1204,23 @@ describe("Clockodo (instance)", () => {
nockScope.done();
});
});

describe("editSurchargeModel()", () => {
it("correctly builds editSurchargeModel() request", async () => {
const entry = {
id: 365,
name: "ABC",
};

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

await clockodo.editSurchargeModel(entry);

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

describe("DELETE", () => {
Expand Down Expand Up @@ -1300,6 +1361,18 @@ describe("Clockodo (instance)", () => {
nockScope.done();
});
});

describe("deleteSurchargeModel()", () => {
it("correctly builds deleteSurchargeModel() request", async () => {
const nockScope = nock(CLOCKODO_API)
.delete("/v2/surchargeModels/31")
.reply(200, {});

await clockodo.deleteSurchargeModel({ id: 31 });

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

Expand Down
55 changes: 55 additions & 0 deletions src/clockodo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
WorkTimeDay,
} from "./models/workTimes.js";
import { OvertimecarryRow } from "./models/overtimecarry.js";
import { SurchargeModel } from "./models/surchargeModel.js";
import { HolidaysQuota } from "./models/holidaysQuota.js";
import { HolidaysCarryover } from "./models/holidaysCarryover.js";

Expand Down Expand Up @@ -369,6 +370,22 @@ export class Clockodo {
return this.api.get("/v2/users", params);
}

async getSurchargeModel(
params: Params<{ id: SurchargeModel["id"] }>
): Promise<SurchargeModelReturnType> {
REQUIRED.checkRequired(params, REQUIRED.GET_SURCHARGE_MODEL);

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

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

async getSurchargeModels(
params?: Params
): Promise<SurchargeModelsReturnType> {
return this.api.get("/v2/surchargeModels", params);
}
anki247 marked this conversation as resolved.
Show resolved Hide resolved

async getUserReport<
GivenUserReportType extends UserReportType = UserReportType.Year
>(
Expand Down Expand Up @@ -499,6 +516,16 @@ export class Clockodo {
return this.api.post("/v2/users", params);
}

async addSurchargeModel(
params: Params<
Pick<SurchargeModel, typeof REQUIRED.ADD_SURCHARGE_MODEL[number]>
>
): Promise<SurchargeModelReturnType> {
REQUIRED.checkRequired(params, REQUIRED.ADD_SURCHARGE_MODEL);

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

async startClock(
params: Params<
Pick<TimeEntry, typeof REQUIRED.START_CLOCK[number]> & {
Expand Down Expand Up @@ -619,6 +646,18 @@ export class Clockodo {
return this.api.put("/v2/users/" + id, params);
}

async editSurchargeModel(
params: Params<
Pick<SurchargeModel, typeof REQUIRED.EDIT_SURCHARGE_MODEL[number]>
>
): Promise<SurchargeModelReturnType> {
REQUIRED.checkRequired(params, REQUIRED.EDIT_SURCHARGE_MODEL);

const { id } = params;

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

async deleteCustomer(
params: Params<Pick<Customer, typeof REQUIRED.DELETE_CUSTOMER[number]>>
): Promise<CustomerReturnType> {
Expand Down Expand Up @@ -659,6 +698,18 @@ export class Clockodo {
return this.api.delete("/v2/users/" + id, params);
}

async deleteSurchargeModel(
params: Params<
Pick<SurchargeModel, typeof REQUIRED.DELETE_SURCHARGE_MODEL[number]>
>
): Promise<DeleteReturnType> {
REQUIRED.checkRequired(params, REQUIRED.DELETE_SURCHARGE_MODEL);

const { id } = params;

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

async deleteAbsence(
params: Params<Pick<Absence, typeof REQUIRED.DELETE_ABSENCE[number]>>
): Promise<DeleteReturnType> {
Expand Down Expand Up @@ -919,6 +970,10 @@ export type LumpsumServicesReturnType = ResponseWithPaging &
};
export type UserReturnType = { user: User };
export type UsersReturnType = { users: Array<User> };
export type SurchargeModelReturnType = { data: SurchargeModel };
export type SurchargeModelsReturnType = {
data: Array<SurchargeModel>;
};
export type EntryReturnType = { entry: Entry };
export type AddEntryReturnType = { entry: Entry; stopped?: Entry };
export type EditEntryReturnType = {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from "./models/nonbusinessGroup.js";
export * from "./models/overtimecarry.js";
export * from "./models/project.js";
export * from "./models/service.js";
export * from "./models/surchargeModel.js";
export * from "./models/targethours.js";
export * from "./models/team.js";
export * from "./models/user.js";
Expand Down
4 changes: 4 additions & 0 deletions src/lib/requiredParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ export const ADD_PROJECT = ["name", "customersId"] as const;
export const ADD_SERVICE = ["name"] as const;
export const ADD_TEAM = ["name"] as const;
export const ADD_USER = ["name", "number", "email", "role"] as const;
export const ADD_SURCHARGE_MODEL = ["name", "accumulation"] as const;
export const CHANGE_CLOCK_DURATION = [
"entriesId",
"durationBefore",
"duration",
] as const;
export const DELETE_SURCHARGE_MODEL = ["id"] as const;
export const DELETE_CUSTOMER = ["id"] as const;
export const DELETE_PROJECT = ["id"] as const;
export const DELETE_USER = ["id"] as const;
Expand All @@ -46,6 +48,7 @@ export const EDIT_PROJECT = ["id"] as const;
export const EDIT_SERVICE = ["id"] as const;
export const EDIT_TEAM = ["id"] as const;
export const EDIT_USER = ["id"] as const;
export const EDIT_SURCHARGE_MODEL = ["id"] as const;
export const EDIT_ENTRY_GROUP = ["timeSince", "timeUntil"] as const;
export const EDIT_ABSENCE = ["id"] as const;
export const EDIT_ENTRY = ["id"] as const;
Expand All @@ -65,6 +68,7 @@ export const GET_LUMPSUM_SERVICE = ["id"] as const;
export const GET_TARGETHOURS_ROW = ["id"] as const;
export const GET_TEAM = ["id"] as const;
export const GET_USER = ["id"] as const;
export const GET_SURCHARGE_MODEL = ["id"] as const;
export const GET_USER_REPORT = ["usersId", "year"] as const;
export const GET_USER_REPORTS = ["year"] as const;
export const GET_NONBUSINESS_DAYS = ["year"] as const;
Expand Down
1 change: 1 addition & 0 deletions src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from "./models/nonbusinessDay.mocks.js";
export * from "./models/overtimecarry.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";
Expand Down
Loading
Loading