Files
adam-acs/app/services/cwmp/action_execution_helper.ts
Kevin L'Hereec f9e56c78b1 refactor: migrate all internal imports to package.json subpath aliases
- Add #domain, #protocol, #utils aliases to package.json imports map
- Replace all relative imports (./, ../, ../..) in app/ and
  database/mongo_migrations/ with the corresponding #alias imports,
  eliminating relative path traversal across the codebase
- Remove dead code: ConfigurationVersionModel.findByConfigurationIdentifier
  (unused, superseded by paginateVersions) and unused exception classes
  (NotFoundException, UnprocessableEntityException, DatabaseException)
  from app/exceptions/index.ts, keeping only BadRequestException
- Fix pre-existing syntax error in configuration_version.ts (mismatched
  parenthesis) that broke tsc
- Fix eqeqeq violation in configuration_service.ts and isNaN ->
  Number.isNaN in configuration_engine.ts / cwmp-1-0.ts / exchange_controller.ts
- Fix no-shadow violation in cwmp-1-0.ts EventStruct constructor
- Prettier formatting pass on touched files

Validated: tsc --noEmit clean, eslint app/ clean, full test suite green.
2026-07-22 11:45:14 +02:00

75 lines
2.1 KiB
TypeScript

import { type Device } from '#domain/device/device'
import { type DeviceActionExecutor } from '#services/cwmp/device_action_executor'
import logger from '@adonisjs/core/services/logger'
/**
* Action types
*/
export enum ActionType {
SET_PARAMETER_VALUES = 'SET_PARAMETER_VALUES',
SET_PARAMETER_ATTRIBUTES = 'SET_PARAMETER_ATTRIBUTES',
SCHEDULE_INFORM = 'SCHEDULE_INFORM',
DOWNLOAD = 'DOWNLOAD',
UPLOAD = 'UPLOAD',
FACTORY_RESET = 'FACTORY_RESET',
REBOOT = 'REBOOT',
}
/**
* Dispatches an action to the corresponding DeviceActionExecutor method
*/
export async function executeAction(
deviceAction: DeviceActionExecutor,
device: Device,
actionType: ActionType,
parameters: any[],
callback: (result: unknown) => Promise<string> = () => Promise.resolve('')
): Promise<string> {
switch (actionType) {
case ActionType.SET_PARAMETER_VALUES:
return deviceAction.applySetParameterValues(
device,
parameters as any[],
callback as (r: boolean) => Promise<string>
)
case ActionType.SET_PARAMETER_ATTRIBUTES:
return deviceAction.applySetParameterAttributes(
device,
parameters as any[],
callback as (r: boolean) => Promise<string>
)
case ActionType.SCHEDULE_INFORM:
return deviceAction.applyScheduleInform(
device,
parameters[0] as any,
callback as (r: boolean) => Promise<string>
)
case ActionType.DOWNLOAD: {
const p = parameters[0]
return deviceAction.applyDownload(device, p, callback as (r: boolean) => Promise<string>)
}
case ActionType.UPLOAD: {
const p = parameters[0]
return deviceAction.applyUpload(device, p, callback as (r: boolean) => Promise<string>)
}
case ActionType.FACTORY_RESET: {
const p = parameters?.[0]
return deviceAction.applyFactoryReset(device, p, callback as (r: boolean) => Promise<string>)
}
case ActionType.REBOOT: {
const p = parameters[0]
return deviceAction.applyReboot(device, p, callback as (r: boolean) => Promise<string>)
}
default:
logger.error(`Unknown action type: ${actionType}`)
return ''
}
}