Skip to content

Commit b49a0ee

Browse files
committed
Topcoder NestJS Autopilot Phase Transition Logic Optimization
1 parent ee6daab commit b49a0ee

File tree

12 files changed

+1363
-109
lines changed

12 files changed

+1363
-109
lines changed

src/autopilot/dto/autopilot.dto.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
IsDateString,
77
IsUUID,
88
} from 'class-validator';
9+
import { AutopilotOperator } from '../interfaces/autopilot.interface';
910

1011
export class PhaseTransitionDto {
1112
@IsDateString()
@@ -23,8 +24,8 @@ export class PhaseTransitionDto {
2324
@IsEnum(['START', 'END'])
2425
state: 'START' | 'END';
2526

26-
@IsString()
27-
operator: string;
27+
@IsEnum(AutopilotOperator)
28+
operator: AutopilotOperator | string;
2829

2930
@IsString()
3031
projectStatus: string;
@@ -40,8 +41,8 @@ export class ChallengeUpdateDto {
4041
@IsString()
4142
status: string;
4243

43-
@IsString()
44-
operator: string;
44+
@IsEnum(AutopilotOperator)
45+
operator: AutopilotOperator | string;
4546
}
4647

4748
export class CommandDto {
@@ -57,6 +58,6 @@ export class CommandDto {
5758
@IsObject()
5859
parameters: Record<string, any>;
5960

60-
@IsString()
61-
operator: string;
61+
@IsEnum(AutopilotOperator)
62+
operator: AutopilotOperator | string;
6263
}

src/autopilot/interfaces/autopilot.interface.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
export enum AutopilotOperator {
2+
// System operators for internal autopilot operations
3+
SYSTEM = 'system',
4+
SYSTEM_SCHEDULER = 'system-scheduler',
5+
SYSTEM_NEW_CHALLENGE = 'system-new-challenge',
6+
SYSTEM_RECOVERY = 'system-recovery',
7+
SYSTEM_SYNC = 'system-sync',
8+
SYSTEM_PHASE_CHAIN = 'system-phase-chain',
9+
10+
// Administrative operators
11+
ADMIN = 'admin',
12+
13+
// User operators (when operator comes from external sources)
14+
USER = 'user',
15+
}
16+
117
export interface BaseMessage {
218
topic: string;
319
originator: string;
@@ -10,7 +26,7 @@ export interface PhaseTransitionPayload {
1026
phaseId: string; // Changed from number to string to support UUIDs from the API
1127
phaseTypeName: string;
1228
state: 'START' | 'END';
13-
operator: string;
29+
operator: AutopilotOperator | string; // Allow both enum and string for flexibility
1430
projectStatus: string;
1531
date?: string;
1632
challengeId: string; // Changed to string to support UUIDs
@@ -20,7 +36,7 @@ export interface ChallengeUpdatePayload {
2036
projectId: number;
2137
challengeId: string; // Changed to string to support UUIDs
2238
status: string;
23-
operator: string;
39+
operator: AutopilotOperator | string; // Allow both enum and string for flexibility
2440
date?: string;
2541
// This nested structure may be present in Kafka messages from the API
2642
phases?: {
@@ -31,7 +47,7 @@ export interface ChallengeUpdatePayload {
3147

3248
export interface CommandPayload {
3349
command: string;
34-
operator: string;
50+
operator: AutopilotOperator | string; // Allow both enum and string for flexibility
3551
projectId?: number;
3652
challengeId?: string; // Added challengeId for new command handling
3753
date?: string;

0 commit comments

Comments
 (0)