- 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.
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import CommandModel from '#models/command'
|
|
import { type CommandRecord, CommandStatus, type CommandType } from '#domain/commands/command'
|
|
import { ModeType } from '#domain/shared/mode'
|
|
import { Priority } from '#domain/commands/command'
|
|
|
|
export default class CommandService {
|
|
async getCommands() {
|
|
const collection = CommandModel.getCollection()
|
|
return collection.find({}).sort({ createdAt: -1 }).toArray()
|
|
}
|
|
|
|
async getCommandsByDevice(deviceIdentifier: string) {
|
|
return CommandModel.findByDevice(deviceIdentifier)
|
|
}
|
|
|
|
async createCommand(data: {
|
|
deviceIdentifier: string
|
|
action: CommandType
|
|
parameters: Record<string, any>
|
|
mode?: ModeType
|
|
priority?: number
|
|
}): Promise<CommandRecord> {
|
|
return CommandModel.createCommand({
|
|
deviceIdentifier: data.deviceIdentifier,
|
|
action: data.action,
|
|
parameters: data.parameters,
|
|
mode: data.mode || ModeType.NI,
|
|
status: CommandStatus.PENDING,
|
|
priority: data.priority ?? Priority.NORMAL,
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
})
|
|
}
|
|
|
|
async getICommandsForDeviceWithStatus(
|
|
deviceIdentifier: string,
|
|
status: CommandStatus
|
|
): Promise<CommandRecord[]> {
|
|
const collection = CommandModel.getCollection()
|
|
return collection
|
|
.find({ deviceIdentifier, mode: ModeType.I, status })
|
|
.sort({ priority: 1 })
|
|
.toArray() as unknown as Promise<CommandRecord[]>
|
|
}
|
|
|
|
async getNICommandsForDeviceWithStatus(
|
|
deviceIdentifier: string,
|
|
status: CommandStatus
|
|
): Promise<CommandRecord[]> {
|
|
const collection = CommandModel.getCollection()
|
|
return collection
|
|
.find({ deviceIdentifier, mode: ModeType.NI, status })
|
|
.sort({ priority: 1 })
|
|
.toArray() as unknown as Promise<CommandRecord[]>
|
|
}
|
|
|
|
async updateCommandStatus(id: any, update: Partial<CommandRecord>): Promise<void> {
|
|
await CommandModel.updateCommand(id, update)
|
|
}
|
|
|
|
async deleteCommand(id: string): Promise<boolean> {
|
|
return CommandModel.deleteById(id)
|
|
}
|
|
}
|