Files
adam-acs/app/services/command_service.ts
T
Kevin L'HereecandCopilot d1c65dbf1e chore: initial commit — AdonisJS v7 TR-069 ACS
- Docker infrastructure (Dockerfile, docker-compose.yml, genieacs-sim)
- AdonisJS v7 app with Inertia.js + Vue 3
- MongoDB integration
- CWMP/TR-069 state machine engine
- Configuration engine with compliance tracking
- Branding: ADAM ACS (favicon, navbar, locales)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-29 16:46:37 +02:00

59 lines
2.0 KiB
TypeScript

import CommandModel from '#models/command'
import { CommandRecord, CommandStatus, CommandType } from '../domain/commands/command.js'
import { ModeType } from '../domain/shared/mode.js'
import { Priority } from '../domain/commands/command.js'
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)
}
}