Skip to content

Commit 502b5e9

Browse files
fix: new date attribute (#63)
* fix: add new date attribute * chore: bump version
1 parent 165aad6 commit 502b5e9

File tree

8 files changed

+65
-12
lines changed

8 files changed

+65
-12
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "factorial-cli",
3-
"version": "1.0.9",
3+
"version": "1.0.10",
44
"type": "module",
55
"description": "Fill your factorial shifts with ease",
66
"main": "dist/src/infrastructure/cli/main.js",
@@ -33,4 +33,4 @@
3333
"yargs": "^17.7.2",
3434
"zod": "^3.22.4"
3535
}
36-
}
36+
}

src/domain/models/Day.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import { PeriodId } from "./PeriodId.js";
33
import { Shift } from "./Shift.js";
44
import { DayRange } from "./DayRange.js";
55
import { DayNumber } from "./DayNumber.js";
6-
import { MonthOfTheYear } from "./MonthOfTheYear.js";
6+
import { MonthOfTheYear, MonthOfTheYearPrimitives } from "./MonthOfTheYear.js";
77
import { EmployeeId } from "./EmployeeId.js";
8+
import { Year } from "./Year.js";
9+
import { MonthNumber } from "./MonthNumber.js";
810

911
export type DayPrimitives = {
12+
monthOfTheYear: MonthOfTheYearPrimitives;
1013
dayNumber: number;
1114
leaves: Array<LeavePrimitives>;
1215
isLaborable: boolean;
@@ -15,17 +18,24 @@ export type DayPrimitives = {
1518
export class Day {
1619
static fromPrimitives(primitives: DayPrimitives) {
1720
return new Day(
21+
MonthOfTheYear.fromPrimitives(primitives.monthOfTheYear),
1822
new DayNumber(primitives.dayNumber),
1923
primitives.leaves.map(Leave.fromPrimitives),
2024
primitives.isLaborable,
2125
);
2226
}
2327

2428
static at(number: number) {
25-
return new Day(new DayNumber(number), [], true);
29+
return new Day(
30+
new MonthOfTheYear(new Year(2024), new MonthNumber(7)),
31+
new DayNumber(number),
32+
[],
33+
true,
34+
);
2635
}
2736

2837
constructor(
38+
private readonly monthOfTheYear: MonthOfTheYear,
2939
private readonly dayNumber: DayNumber,
3040
private readonly leaves: Leave[],
3141
private readonly isLaborable: boolean,
@@ -44,7 +54,13 @@ export class Day {
4454
currentPeriodId: PeriodId,
4555
dayRange: DayRange,
4656
) {
47-
return Shift.create(employeeId, this.dayNumber, currentPeriodId, dayRange);
57+
return Shift.create(
58+
employeeId,
59+
this.dayNumber,
60+
currentPeriodId,
61+
dayRange,
62+
this.monthOfTheYear,
63+
);
4864
}
4965

5066
toDate(monthOfTheYear: MonthOfTheYear) {

src/domain/models/Shift.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Primitives } from "../../shared/Primitives.js";
55
import { DayNumber } from "./DayNumber.js";
66
import { EmployeeId } from "./EmployeeId.js";
77
import { ProjectId } from "./ProjectId.js";
8+
import { MonthOfTheYear } from "./MonthOfTheYear.js";
89

910
export type ShiftPrimitives = Primitives<Shift>;
1011

@@ -16,6 +17,7 @@ export class Shift {
1617
new DayNumber(primitives.dayNumber),
1718
PeriodId.fromPrimitives(primitives.currentPeriodId),
1819
DayRange.fromPrimitives(primitives.dayRange),
20+
MonthOfTheYear.fromPrimitives(primitives.monthOfTheYear),
1921
primitives.projectId ? new ProjectId(primitives.projectId) : undefined,
2022
);
2123
}
@@ -25,8 +27,16 @@ export class Shift {
2527
value: DayNumber,
2628
currentPeriodId: PeriodId,
2729
dayRange: DayRange,
30+
monthOfTheYear: MonthOfTheYear,
2831
) {
29-
return new Shift(null as any, employeeId, value, currentPeriodId, dayRange);
32+
return new Shift(
33+
null as any,
34+
employeeId,
35+
value,
36+
currentPeriodId,
37+
dayRange,
38+
monthOfTheYear,
39+
);
3040
}
3141

3242
constructor(
@@ -35,6 +45,7 @@ export class Shift {
3545
private readonly dayNumber: DayNumber,
3646
private readonly currentPeriodId: PeriodId,
3747
private readonly dayRange: DayRange,
48+
private readonly monthOfTheYear: MonthOfTheYear,
3849
private projectId?: ProjectId,
3950
) {}
4051

@@ -53,6 +64,7 @@ export class Shift {
5364
dayNumber: this.dayNumber.toPrimitives(),
5465
currentPeriodId: this.currentPeriodId.toPrimitives(),
5566
dayRange: this.dayRange.toPrimitives(),
67+
monthOfTheYear: this.monthOfTheYear.toPrimitives(),
5668
projectId: this.projectId?.toPrimitives(),
5769
};
5870
}

src/infrastructure/factorial-client/FactorialClient.integration-test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe("FactorialClient", () => {
5353
let periodId: number;
5454
const year = new Date().getFullYear();
5555
const month = new Date().getMonth() + 1;
56+
const date = `${year}-${month.toString().padStart(2, "0")}-18`;
5657

5758
beforeEach(async () => {
5859
const periods = await client.getPeriods(employeeId, year, month);
@@ -72,6 +73,7 @@ describe("FactorialClient", () => {
7273
clockOutHour: 16,
7374
clockOutMinutes: 0,
7475
day: 18,
76+
date,
7577
});
7678

7779
const shifts = await client.getShifts(employeeId, periodId, year, month);
@@ -86,6 +88,7 @@ describe("FactorialClient", () => {
8688
clockOutHour: 16,
8789
clockOutMinutes: 0,
8890
day: 18,
91+
date,
8992
});
9093
const secretProjectId = 116990;
9194

@@ -100,6 +103,7 @@ describe("FactorialClient", () => {
100103
clockOutHour: 16,
101104
clockOutMinutes: 0,
102105
day: 18,
106+
date,
103107
});
104108

105109
await client.deleteShift(shiftId);

src/infrastructure/factorial-client/FactorialClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,22 @@ export class FactorialClient {
137137
clockOutHour,
138138
clockOutMinutes,
139139
day,
140+
date,
140141
}: {
141142
periodId: number;
142143
clockInHour: number;
143144
clockInMinutes: number;
144145
clockOutHour: number;
145146
clockOutMinutes: number;
146147
day: number;
148+
date: string;
147149
}) {
148150
const response = await this.client.post("/attendance/shifts", {
149151
period_id: periodId,
150152
clock_in: `${clockInHour}:${clockInMinutes}`,
151153
clock_out: `${clockOutHour}:${clockOutMinutes}`,
152154
minutes: 0,
155+
date,
153156
day,
154157
observations: null,
155158
history: [],

src/infrastructure/http-client/HttpClientFetch.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ export class HttpClientFetch implements HttpClient {
104104
headers[key] = value;
105105
});
106106

107-
const data: T = headers["content-type"].includes("json")
108-
? await response.json()
109-
: await response.text();
107+
const data: T =
108+
headers["content-type"].includes("json") && response.status !== 400
109+
? await response.json()
110+
: await response.text();
110111

111112
if (response.status >= 400) {
112113
throw new HttpClientError({

src/infrastructure/repositories/MonthRepositoryFactorial.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { FactorialClient } from "../factorial-client/FactorialClient.js";
22
import { EmployeeId } from "../../domain/models/EmployeeId.js";
3-
import { MonthOfTheYear } from "../../domain/models/MonthOfTheYear.js";
3+
import {
4+
MonthOfTheYear,
5+
MonthOfTheYearPrimitives,
6+
} from "../../domain/models/MonthOfTheYear.js";
47
import { Month } from "../../domain/models/Month.js";
58
import { CalendarDay } from "../factorial-client/schema/CalendarDay.js";
69
import { DayPrimitives } from "../../domain/models/Day.js";
@@ -24,15 +27,21 @@ export class MonthRepositoryFactorial implements MonthRepository {
2427

2528
return Month.fromPrimitives({
2629
monthOfTheYear: monthOfTheYear.toPrimitives(),
27-
days: calendar.map(MonthRepositoryFactorial.dayToDomain),
30+
days: calendar.map((d) =>
31+
MonthRepositoryFactorial.dayToDomain(d, monthOfTheYear.toPrimitives()),
32+
),
2833
});
2934
}
3035

31-
private static dayToDomain(day: CalendarDay): DayPrimitives {
36+
private static dayToDomain(
37+
day: CalendarDay,
38+
monthOfTheYear: MonthOfTheYearPrimitives,
39+
): DayPrimitives {
3240
return {
3341
dayNumber: day.day,
3442
leaves: day.leaves.map(MonthRepositoryFactorial.leaveToDomain),
3543
isLaborable: day.isLaborable,
44+
monthOfTheYear,
3645
};
3746
}
3847

src/infrastructure/repositories/ShiftRepositoryFactorial.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@ export class ShiftRepositoryFactorial implements ShiftRepository {
1313
async save(shift: Shift) {
1414
const primitives = shift.toPrimitives();
1515

16+
const date =
17+
primitives.monthOfTheYear.year +
18+
"-" +
19+
primitives.monthOfTheYear.month.toString().padStart(2, "0") +
20+
"-" +
21+
primitives.dayNumber.toString().padStart(2, "0");
1622
const shiftId = await this.factorial.createShift({
1723
periodId: primitives.currentPeriodId,
1824
clockInHour: primitives.dayRange.start.hour,
1925
clockInMinutes: primitives.dayRange.start.minute,
2026
clockOutHour: primitives.dayRange.end.hour,
2127
clockOutMinutes: primitives.dayRange.end.minute,
2228
day: primitives.dayNumber,
29+
date,
2330
});
2431

2532
// @ts-ignore
@@ -68,6 +75,7 @@ export class ShiftRepositoryFactorial implements ShiftRepository {
6875
minute: 0,
6976
},
7077
},
78+
monthOfTheYear: {} as any, // TODO
7179
});
7280
}
7381
}

0 commit comments

Comments
 (0)