Skip to content

Commit

Permalink
renamed surcharge to surchargeModel
Browse files Browse the repository at this point in the history
  • Loading branch information
dsumer committed Oct 18, 2023
1 parent ed3783e commit e70cdb5
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 44 deletions.
30 changes: 15 additions & 15 deletions src/clockodo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,25 +593,25 @@ describe("Clockodo (instance)", () => {
});
});

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

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

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

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

await clockodo.getSurcharges();
await clockodo.getSurchargeModels();

nockScope.done();
});
Expand Down Expand Up @@ -896,8 +896,8 @@ describe("Clockodo (instance)", () => {
});
});

describe("addSurcharge()", () => {
it("correctly builds addSurcharge() request", async () => {
describe("addSurchargeModel()", () => {
it("correctly builds addSurchargeModel() request", async () => {
const expectedParameters = {
name: "Weyland-Yutani",
accumulation: true,
Expand All @@ -907,7 +907,7 @@ describe("Clockodo (instance)", () => {
.post("/v2/surcharges", expectedParameters)
.reply(200, {});

await clockodo.addSurcharge({
await clockodo.addSurchargeModel({

Check failure on line 910 in src/clockodo.test.ts

View workflow job for this annotation

GitHub Actions / test-and-release (16.x)

Property 'addSurchargeModel' does not exist on type 'Clockodo'. Did you mean 'editSurchargeModel'?

Check failure on line 910 in src/clockodo.test.ts

View workflow job for this annotation

GitHub Actions / test-and-release (18.x)

Property 'addSurchargeModel' does not exist on type 'Clockodo'. Did you mean 'editSurchargeModel'?
name: "Weyland-Yutani",
accumulation: true,
});
Expand Down Expand Up @@ -1072,8 +1072,8 @@ describe("Clockodo (instance)", () => {
});
});

describe("editSurcharge()", () => {
it("correctly builds editSurcharge() request", async () => {
describe("editSurchargeModel()", () => {
it("correctly builds editSurchargeModel() request", async () => {
const entry = {
id: 365,
name: "ABC",
Expand All @@ -1083,7 +1083,7 @@ describe("Clockodo (instance)", () => {
.put("/v2/surcharges/365", mapRequestBody(entry))
.reply(200, {});

await clockodo.editSurcharge(entry);
await clockodo.editSurchargeModel(entry);

nockScope.done();
});
Expand Down Expand Up @@ -1215,13 +1215,13 @@ describe("Clockodo (instance)", () => {
});
});

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

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

nockScope.done();
});
Expand Down
44 changes: 26 additions & 18 deletions src/clockodo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
WorkTimeChangeRequestStatus,
WorkTimeDay,
} from "./models/workTimes.js";
import { Surcharge } from "./models/surcharge.js";
import { SurchargeModel } from "./models/surchargeModel.js";

export class Clockodo {
api: Api;
Expand Down Expand Up @@ -330,17 +330,19 @@ export class Clockodo {
return this.api.get("/users", params);
}

async getSurcharge(
params: Params<{ id: Surcharge["id"] }>
): Promise<SurchargeReturnType> {
REQUIRED.checkRequired(params, REQUIRED.GET_SURCHARGE);
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/surcharges/" + id, remainingParams);
}

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

Expand Down Expand Up @@ -465,9 +467,11 @@ export class Clockodo {
}

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

return this.api.post("/v2/surcharges", params);
}
Expand Down Expand Up @@ -580,10 +584,12 @@ export class Clockodo {
return this.api.put("/users/" + id, params);
}

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

const { id } = params;

Expand Down Expand Up @@ -630,10 +636,12 @@ export class Clockodo {
return this.api.delete("/users/" + id, params);
}

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

const { id } = params;

Expand Down Expand Up @@ -853,8 +861,8 @@ export type LumpsumServicesReturnType = {
};
export type UserReturnType = { user: User };
export type UsersReturnType = { users: Array<User> };
export type SurchargeReturnType = { surcharge: Surcharge };
export type SurchargesReturnType = { surcharges: Array<Surcharge> };
export type SurchargeModelReturnType = { surcharge: SurchargeModel };
export type SurchargeModelsReturnType = { surcharges: Array<SurchargeModel> };
export type EntryReturnType = { entry: Entry };
export type AddEntryReturnType = { entry: Entry; stopped?: Entry };
export type EditEntryReturnType = {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export * from "./models/nonbusinessDay.js";
export * from "./models/nonbusinessGroup.js";
export * from "./models/project.js";
export * from "./models/service.js";
export * from "./models/surcharge.js";
export * from "./models/surchargeModel.js";
export * from "./models/targethours.js";
export * from "./models/team.js";
export * from "./models/user.js";
Expand Down
8 changes: 4 additions & 4 deletions src/lib/requiredParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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 = ["name", "accumulation"] as const;
export const ADD_SURCHARGE_MODEL = ["name", "accumulation"] as const;
export const CHANGE_CLOCK_DURATION = [
"entriesId",
"durationBefore",
Expand All @@ -35,7 +35,7 @@ export const DEACTIVATE_CUSTOMER = ["id"] as const;
export const DEACTIVATE_PROJECT = ["id"] as const;
export const DEACTIVATE_SERVICE = ["id"] as const;
export const DEACTIVATE_USER = ["id"] as const;
export const DELETE_SURCHARGE = ["id"] as const;
export const DELETE_SURCHARGE_MODEL = ["id"] as const;
export const DELETE_ENTRY = ["id"] as const;
export const DELETE_ENTRY_GROUP = ["timeSince", "timeUntil"] as const;
export const DELETE_ABSENCE = ["id"] as const;
Expand All @@ -45,7 +45,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 = ["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,7 +65,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 = ["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
2 changes: 1 addition & 1 deletion src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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/surcharge.mocks.js";
export * from "./models/surchargeModel.mocks.js";
export * from "./models/targethours.mocks.js";
export * from "./models/user.mocks.js";
// export * from "./models/userReport.mocks.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { faker } from "@faker-js/faker";
import { Surcharge } from "./surcharge.js";
import { SurchargeModel } from "./surchargeModel.js";

export const createSurchargeMocks = ({ count = 1 }: { count?: number } = {}) =>
Array.from({ length: count }, (_, index): Surcharge => {
export const createSurchargeModelMocks = ({
count = 1,
}: { count?: number } = {}) =>
Array.from({ length: count }, (_, index): SurchargeModel => {
return {
id: index,
name: faker.commerce.productName(),
Expand Down
2 changes: 1 addition & 1 deletion src/models/surcharge.ts → src/models/surchargeModel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsoTime } from "./dateTime.js";

export type Surcharge = {
export type SurchargeModel = {
/** The ID of the surcharge model */
id: number;
/** The name of the surcharge model */
Expand Down
4 changes: 3 additions & 1 deletion src/models/targethours.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ export const createTargethoursRowMonthlyMocks = ({
? null
: isoDateFromDateTime(endOfMonth(new Date(to))),
type: TargethoursRowType.Monthly,
monthlyTarget: faker.datatype.number(),
monthlyTarget: parseFloat(
faker.datatype.float({ min: 0, max: 744 }).toFixed(2)
),
workdayMonday: faker.datatype.boolean(),
workdayTuesday: faker.datatype.boolean(),
workdayWednesday: faker.datatype.boolean(),
Expand Down

0 comments on commit e70cdb5

Please sign in to comment.