feat(G1,P16A,P16B): 收口主数据核心与节假日日历增强
这个提交包含在:
+60
-1
@@ -3,9 +3,11 @@ const { z } = require("zod");
|
||||
const { AppError } = require("../utils/AppError");
|
||||
const { sendData } = require("../utils/reply");
|
||||
const { resolveActionableStep } = require("../utils/workflow");
|
||||
const { FEATURE_FLAG_KEYS, evaluateFeatureFlag } = require("../services/featureFlags");
|
||||
const {
|
||||
DEFAULT_ATTACHMENT_MIME_TYPES,
|
||||
calculateRequestedDays,
|
||||
calculateRequestedDaysByWorkingCalendar,
|
||||
createLeaveLedgerEntry,
|
||||
formatDateOnly,
|
||||
leaveRangesOverlap,
|
||||
@@ -165,6 +167,61 @@ function parseCreateBody(body) {
|
||||
};
|
||||
}
|
||||
|
||||
async function resolveRequestedDaysForCreate(fastify, employee, body) {
|
||||
if (!employee?.legal_entity_id) {
|
||||
return body.requestedDays;
|
||||
}
|
||||
|
||||
const featureFlag = await evaluateFeatureFlag({
|
||||
prisma: fastify.prisma,
|
||||
config: fastify.config,
|
||||
flagKey: FEATURE_FLAG_KEYS.leaveHolidayCalendar,
|
||||
departmentId: employee.department_id ?? null,
|
||||
strictDepartment: false,
|
||||
});
|
||||
|
||||
if (!featureFlag.enabled) {
|
||||
return body.requestedDays;
|
||||
}
|
||||
|
||||
const legalEntity = await fastify.prisma.legalEntity.findUnique({
|
||||
where: { id: employee.legal_entity_id },
|
||||
select: {
|
||||
default_holiday_calendar: {
|
||||
select: {
|
||||
id: true,
|
||||
archived_at: true,
|
||||
days: {
|
||||
where: {
|
||||
date: {
|
||||
gte: body.startDate,
|
||||
lte: body.endDate,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
date: true,
|
||||
day_type: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const calendar = legalEntity?.default_holiday_calendar;
|
||||
if (!calendar || calendar.archived_at) {
|
||||
return body.requestedDays;
|
||||
}
|
||||
|
||||
return calculateRequestedDaysByWorkingCalendar({
|
||||
startDate: body.startDate,
|
||||
endDate: body.endDate,
|
||||
startSession: body.startSession,
|
||||
endSession: body.endSession,
|
||||
calendarDays: calendar.days,
|
||||
});
|
||||
}
|
||||
|
||||
async function collectCreatePayload(request) {
|
||||
if (typeof request.isMultipart === "function" && request.isMultipart()) {
|
||||
const fields = {};
|
||||
@@ -428,6 +485,8 @@ async function leaveRoutes(fastify) {
|
||||
request.employee.id,
|
||||
);
|
||||
|
||||
const requestedDays = await resolveRequestedDaysForCreate(fastify, request.employee, body);
|
||||
|
||||
const leave = await fastify.prisma.leaveRequest.create({
|
||||
data: {
|
||||
owner_id: request.employee.id,
|
||||
@@ -437,7 +496,7 @@ async function leaveRoutes(fastify) {
|
||||
end_date: body.endDate,
|
||||
start_session: body.startSession,
|
||||
end_session: body.endSession,
|
||||
requested_days: body.requestedDays,
|
||||
requested_days: requestedDays,
|
||||
reason: body.reason,
|
||||
attachment_storage_path: attachment?.storagePath ?? null,
|
||||
attachment_original_name: attachment?.originalName ?? null,
|
||||
|
||||
在新工单中引用
屏蔽一个用户