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>
This commit is contained in:
commit
d1c65dbf1e
164 files changed
+29127
No files matched your search
@@ -0,0 +1,39 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user