feat(rfa): complete RFA Approval Refactor - all 9 phases (T001-T080)
Phase 1-2: Setup, SQL schema, enums, queue constants, base entities
Phase 3 (US1): ReviewTeam, ReviewTeamMember, ReviewTask, TaskCreationService
Phase 4 (US2): ResponseCode, ResponseCodeRule, ImplicationsService, NotificationTriggerService
Phase 5 (US3): Delegation entity, CircularDetectionService, DelegationService/Controller/Module
Phase 6 (US4): ReminderRule, SchedulerService, EscalationService, ReminderProcessor, ReminderModule
Phase 7 (US5): DistributionMatrix, DistributionRecipient, ApprovalListenerService (Strangler),
TransmittalCreatorService, DistributionProcessor, DistributionModule
Phase 8 (US6): MatrixManagementService, InheritanceService (global→project override)
Phase 9 (Polish): AggregateStatusService, ConsensusService, VetoOverrideService,
ParallelGatewayHandler, review-validators, optimistic locking in completeReview,
test stubs (unit/integration/e2e), jest.config.js updated for tests/ directory
Frontend: ReviewTaskInbox, ParallelProgress, VetoOverrideDialog, DelegationForm,
DelegatedBadge, MatrixEditor, ProjectOverrideManager, DistributionStatus,
ReminderHistory, ResponseCodeSelector, CodeImplications, CompleteReviewForm,
ReviewTeamForm, ReviewTeamSelector, TeamMemberManager
Closes #1
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
// File: src/common/validators/review-validators.ts
|
||||
// Edge case validators สำหรับ RFA Review workflow (T073)
|
||||
|
||||
/**
|
||||
* ตรวจสอบว่า due date ถูกต้อง (ต้องอยู่ในอนาคต)
|
||||
*/
|
||||
export function validateDueDate(dueDate: Date): void {
|
||||
const now = new Date();
|
||||
if (dueDate <= now) {
|
||||
throw new Error('Due date must be in the future');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ตรวจสอบ delegation date range ไม่เกิน 90 วัน
|
||||
*/
|
||||
export function validateDelegationDateRange(startDate: Date, endDate: Date): void {
|
||||
if (endDate <= startDate) {
|
||||
throw new Error('End date must be after start date');
|
||||
}
|
||||
|
||||
const maxDays = 90;
|
||||
const diffMs = endDate.getTime() - startDate.getTime();
|
||||
const diffDays = Math.floor(diffMs / 86_400_000);
|
||||
|
||||
if (diffDays > maxDays) {
|
||||
throw new Error(`Delegation period cannot exceed ${maxDays} days`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ตรวจสอบ ReviewTask ว่าสามารถ complete ได้ (ต้องมี response code)
|
||||
*/
|
||||
export function validateTaskCompletionRequirements(
|
||||
taskStatus: string,
|
||||
responseCodeId: number | undefined | null,
|
||||
requiresComments: boolean,
|
||||
comments: string | undefined | null,
|
||||
): void {
|
||||
if (taskStatus === 'COMPLETED') {
|
||||
if (!responseCodeId) {
|
||||
throw new Error('Response code is required to complete a review task');
|
||||
}
|
||||
|
||||
if (requiresComments && (!comments || comments.trim().length === 0)) {
|
||||
throw new Error('Comments are required for this response code');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ตรวจสอบ version สำหรับ optimistic locking (ADR-002)
|
||||
*/
|
||||
export function validateVersion(
|
||||
expectedVersion: number,
|
||||
actualVersion: number,
|
||||
entityName: string,
|
||||
): void {
|
||||
if (actualVersion !== expectedVersion) {
|
||||
throw new Error(
|
||||
`Optimistic lock conflict on ${entityName}: expected version ${expectedVersion}, got ${actualVersion}. Please retry.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ตรวจสอบว่า override reason มีความยาวเพียงพอ
|
||||
*/
|
||||
export function validateOverrideReason(reason: string, minLength = 10): void {
|
||||
if (!reason || reason.trim().length < minLength) {
|
||||
throw new Error(`Override reason must be at least ${minLength} characters`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user