Files
adam-acs/app/models/command.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

40 lines
1.7 KiB
TypeScript

import { BaseModel } from '#database/base_model'
import { CommandRecord, CommandStatus } from '../domain/commands/command.js'
import { ModeType } from '../domain/shared/mode.js'
import { ObjectId } from 'mongodb'
export default class CommandModel extends BaseModel {
static collectionName = 'commands'
static async findByDevice(deviceIdentifier: string): Promise<CommandRecord[]> {
const collection = this.getCollection()
return collection.find({ deviceIdentifier }).sort({ createdAt: -1 }).toArray() as unknown as Promise<CommandRecord[]>
}
static async findPending(deviceIdentifier: string, mode?: ModeType): Promise<CommandRecord[]> {
const filter: any = { deviceIdentifier, status: CommandStatus.PENDING }
if (mode) filter.mode = mode
const collection = this.getCollection()
return collection.find(filter).sort({ priority: 1 }).toArray() as unknown as Promise<CommandRecord[]>
}
static async createCommand(command: Omit<CommandRecord, '_id'>): Promise<CommandRecord> {
const collection = this.getCollection()
const doc = { ...command, createdAt: new Date(), updatedAt: new Date() }
const result = await collection.insertOne(doc)
return { ...doc, _id: result.insertedId } as CommandRecord
}
static async updateCommand(id: ObjectId, update: Partial<CommandRecord>): Promise<void> {
const collection = this.getCollection()
await collection.updateOne({ _id: id }, { $set: { ...update, updatedAt: new Date() } })
}
static async deleteById(id: string | ObjectId): Promise<boolean> {
const collection = this.getCollection()
const objectId = typeof id === 'string' ? new ObjectId(id) : id
const result = await collection.deleteOne({ _id: objectId })
return result.deletedCount === 1
}
}