R62 Fix A1-A6:请假预览全非工作日处理
这个提交包含在:
+11
-3
@@ -233,10 +233,13 @@ function buildNaturalWorkingDaysPreview(body) {
|
||||
weekendDayCount: 0,
|
||||
adjustedWorkdayCount: 0,
|
||||
calendarApplied: false,
|
||||
isNonWorkingRange: false,
|
||||
};
|
||||
}
|
||||
|
||||
async function resolveWorkingDaysPreview(fastify, employee, body) {
|
||||
async function resolveWorkingDaysPreview(fastify, employee, body, options = {}) {
|
||||
const allowNonWorkingRange = Boolean(options.allowNonWorkingRange);
|
||||
|
||||
if (!employee?.legal_entity_id) {
|
||||
return buildNaturalWorkingDaysPreview(body);
|
||||
}
|
||||
@@ -288,11 +291,14 @@ async function resolveWorkingDaysPreview(fastify, employee, body) {
|
||||
startSession: body.startSession,
|
||||
endSession: body.endSession,
|
||||
calendarDays: calendar.days,
|
||||
allowNonWorkingRange,
|
||||
});
|
||||
}
|
||||
|
||||
async function resolveRequestedDaysForCreate(fastify, employee, body) {
|
||||
const preview = await resolveWorkingDaysPreview(fastify, employee, body);
|
||||
const preview = await resolveWorkingDaysPreview(fastify, employee, body, {
|
||||
allowNonWorkingRange: false,
|
||||
});
|
||||
return preview.requestedDays;
|
||||
}
|
||||
|
||||
@@ -579,7 +585,9 @@ async function leaveRoutes(fastify) {
|
||||
},
|
||||
async (request, reply) => {
|
||||
const query = parseWorkingDaysPreviewQuery(request.query);
|
||||
const preview = await resolveWorkingDaysPreview(fastify, request.employee, query);
|
||||
const preview = await resolveWorkingDaysPreview(fastify, request.employee, query, {
|
||||
allowNonWorkingRange: true,
|
||||
});
|
||||
|
||||
return sendData(reply, request, preview);
|
||||
},
|
||||
|
||||
+15
-1
@@ -140,6 +140,7 @@ function calculateRequestedDaysPreviewByWorkingCalendar({
|
||||
startSession,
|
||||
endSession,
|
||||
calendarDays = [],
|
||||
allowNonWorkingRange = false,
|
||||
}) {
|
||||
const naturalRequestedDays = calculateRequestedDays({
|
||||
startDate,
|
||||
@@ -184,7 +185,19 @@ function calculateRequestedDaysPreviewByWorkingCalendar({
|
||||
}
|
||||
|
||||
if (requestedUnits <= 0) {
|
||||
throw buildLeaveValidationError({ leave: "non_working_range" });
|
||||
if (!allowNonWorkingRange) {
|
||||
throw buildLeaveValidationError({ leave: "non_working_range" });
|
||||
}
|
||||
|
||||
return {
|
||||
requestedDays: 0,
|
||||
naturalRequestedDays,
|
||||
holidayDayCount: fromHalfDayUnits(holidayUnits),
|
||||
weekendDayCount: fromHalfDayUnits(weekendUnits),
|
||||
adjustedWorkdayCount: fromHalfDayUnits(adjustedWorkdayUnits),
|
||||
calendarApplied: true,
|
||||
isNonWorkingRange: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -194,6 +207,7 @@ function calculateRequestedDaysPreviewByWorkingCalendar({
|
||||
weekendDayCount: fromHalfDayUnits(weekendUnits),
|
||||
adjustedWorkdayCount: fromHalfDayUnits(adjustedWorkdayUnits),
|
||||
calendarApplied: true,
|
||||
isNonWorkingRange: false,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -136,6 +136,7 @@ describe("leave working-days route", () => {
|
||||
weekendDayCount: 0,
|
||||
adjustedWorkdayCount: 1,
|
||||
calendarApplied: true,
|
||||
isNonWorkingRange: false,
|
||||
});
|
||||
|
||||
await app.close();
|
||||
@@ -158,6 +159,44 @@ describe("leave working-days route", () => {
|
||||
weekendDayCount: 0,
|
||||
adjustedWorkdayCount: 0.5,
|
||||
calendarApplied: true,
|
||||
isNonWorkingRange: false,
|
||||
});
|
||||
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it("returns zero days instead of error for fully non-working preview ranges", async () => {
|
||||
const { app } = await buildApp({
|
||||
legalEntity: buildLegalEntity({
|
||||
default_holiday_calendar: {
|
||||
id: "calendar-1",
|
||||
archived_at: null,
|
||||
days: [
|
||||
buildCalendarDay("2026-05-01", "holiday"),
|
||||
buildCalendarDay("2026-05-02", "holiday"),
|
||||
buildCalendarDay("2026-05-03", "holiday"),
|
||||
buildCalendarDay("2026-05-04", "holiday"),
|
||||
buildCalendarDay("2026-05-05", "holiday"),
|
||||
],
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
const response = await app.inject({
|
||||
method: "GET",
|
||||
url: "/api/leave-requests/working-days?startDate=2026-05-01&endDate=2026-05-05&startSession=am&endSession=pm",
|
||||
headers: { authorization: "Bearer test" },
|
||||
});
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
expect(response.json().data).toEqual({
|
||||
requestedDays: 0,
|
||||
naturalRequestedDays: 5,
|
||||
holidayDayCount: 5,
|
||||
weekendDayCount: 0,
|
||||
adjustedWorkdayCount: 0,
|
||||
calendarApplied: true,
|
||||
isNonWorkingRange: true,
|
||||
});
|
||||
|
||||
await app.close();
|
||||
@@ -182,6 +221,7 @@ describe("leave working-days route", () => {
|
||||
weekendDayCount: 0,
|
||||
adjustedWorkdayCount: 0,
|
||||
calendarApplied: false,
|
||||
isNonWorkingRange: false,
|
||||
});
|
||||
expect(featureFlagFindUnique).not.toHaveBeenCalled();
|
||||
expect(legalEntityFindUnique).not.toHaveBeenCalled();
|
||||
|
||||
@@ -121,6 +121,7 @@ describe("Leave Service", () => {
|
||||
weekendDayCount: 0,
|
||||
adjustedWorkdayCount: 1,
|
||||
calendarApplied: true,
|
||||
isNonWorkingRange: false,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -143,6 +144,34 @@ describe("Leave Service", () => {
|
||||
weekendDayCount: 0,
|
||||
adjustedWorkdayCount: 0.5,
|
||||
calendarApplied: true,
|
||||
isNonWorkingRange: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("returns zero-day preview for fully non-working ranges when explicitly allowed", () => {
|
||||
expect(
|
||||
calculateRequestedDaysPreviewByWorkingCalendar({
|
||||
startDate: "2026-05-01",
|
||||
endDate: "2026-05-05",
|
||||
startSession: "am",
|
||||
endSession: "pm",
|
||||
allowNonWorkingRange: true,
|
||||
calendarDays: [
|
||||
{ date: "2026-05-01", day_type: "holiday" },
|
||||
{ date: "2026-05-02", day_type: "holiday" },
|
||||
{ date: "2026-05-03", day_type: "holiday" },
|
||||
{ date: "2026-05-04", day_type: "holiday" },
|
||||
{ date: "2026-05-05", day_type: "holiday" },
|
||||
],
|
||||
}),
|
||||
).toEqual({
|
||||
requestedDays: 0,
|
||||
naturalRequestedDays: 5,
|
||||
holidayDayCount: 5,
|
||||
weekendDayCount: 0,
|
||||
adjustedWorkdayCount: 0,
|
||||
calendarApplied: true,
|
||||
isNonWorkingRange: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
在新工单中引用
屏蔽一个用户