Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/autopilot/dto/autopilot.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IsDateString,
IsUUID,
} from 'class-validator';
import { AutopilotOperator } from '../interfaces/autopilot.interface';

export class PhaseTransitionDto {
@IsDateString()
Expand All @@ -23,8 +24,8 @@ export class PhaseTransitionDto {
@IsEnum(['START', 'END'])
state: 'START' | 'END';

@IsString()
operator: string;
@IsEnum(AutopilotOperator)
operator: AutopilotOperator | string;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing the | string union type if AutopilotOperator already includes all possible string values for operator. This will ensure type safety and prevent any unexpected values.


@IsString()
projectStatus: string;
Expand All @@ -40,8 +41,8 @@ export class ChallengeUpdateDto {
@IsString()
status: string;

@IsString()
operator: string;
@IsEnum(AutopilotOperator)
operator: AutopilotOperator | string;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing the | string union type if operator should strictly be an AutopilotOperator. Allowing both AutopilotOperator and string could lead to potential type inconsistencies.

}

export class CommandDto {
Expand All @@ -57,6 +58,6 @@ export class CommandDto {
@IsObject()
parameters: Record<string, any>;

@IsString()
operator: string;
@IsEnum(AutopilotOperator)
operator: AutopilotOperator | string;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type for operator has been changed to AutopilotOperator | string. Consider whether allowing both AutopilotOperator and string is necessary. If AutopilotOperator is an enum, it might be beneficial to restrict the type to just AutopilotOperator to ensure type safety and prevent invalid values.

}
22 changes: 19 additions & 3 deletions src/autopilot/interfaces/autopilot.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
export enum AutopilotOperator {
// System operators for internal autopilot operations
SYSTEM = 'system',
SYSTEM_SCHEDULER = 'system-scheduler',
SYSTEM_NEW_CHALLENGE = 'system-new-challenge',
SYSTEM_RECOVERY = 'system-recovery',
SYSTEM_SYNC = 'system-sync',
SYSTEM_PHASE_CHAIN = 'system-phase-chain',

// Administrative operators
ADMIN = 'admin',

// User operators (when operator comes from external sources)
USER = 'user',
}

export interface BaseMessage {
topic: string;
originator: string;
Expand All @@ -10,7 +26,7 @@ export interface PhaseTransitionPayload {
phaseId: string; // Changed from number to string to support UUIDs from the API
phaseTypeName: string;
state: 'START' | 'END';
operator: string;
operator: AutopilotOperator | string; // Allow both enum and string for flexibility

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider documenting the AutopilotOperator enum to ensure clarity on what values are expected when using the enum type. This will help maintain consistency and prevent errors when using string values that may not match the enum.

projectStatus: string;
date?: string;
challengeId: string; // Changed to string to support UUIDs
Expand All @@ -20,7 +36,7 @@ export interface ChallengeUpdatePayload {
projectId: number;
challengeId: string; // Changed to string to support UUIDs
status: string;
operator: string;
operator: AutopilotOperator | string; // Allow both enum and string for flexibility

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider documenting the AutopilotOperator enum to ensure clarity on what values are expected when using this type. This will help maintain consistency and prevent errors when using the operator field.

date?: string;
// This nested structure may be present in Kafka messages from the API
phases?: {
Expand All @@ -31,7 +47,7 @@ export interface ChallengeUpdatePayload {

export interface CommandPayload {
command: string;
operator: string;
operator: AutopilotOperator | string; // Allow both enum and string for flexibility

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider documenting the AutopilotOperator enum to clarify its possible values and usage, ensuring that developers understand the flexibility intended by allowing both enum and string types for operator. This will help maintain consistency and prevent potential errors when using the operator field.

projectId?: number;
challengeId?: string; // Added challengeId for new command handling
date?: string;
Expand Down
Loading