R62 Fix A1-A6:请假预览全非工作日处理

这个提交包含在:
2026-04-14 12:55:27 +08:00
父节点 f8d941ec64
当前提交 c90cb165be
共修改 7 个文件,包含 114 行新增和 6 行删除
+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,
};
}