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

45 lines
1.8 KiB
TypeScript

import { BaseModel } from '#database/base_model'
import { type CommandRecord, CommandStatus } from '#domain/commands/command'
import { type ModeType } from '#domain/shared/mode'
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 (await 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
}
}