- 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>
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { BaseModel } from '#database/base_model'
|
|
import { Configuration } from '../domain/configuration/configuration.js'
|
|
import { Filter, Sort } from 'mongodb'
|
|
|
|
export default class ConfigurationModel extends BaseModel {
|
|
static collectionName = 'configurations'
|
|
|
|
static async findByIdentifier(identifier: string): Promise<Configuration | null> {
|
|
return this.findOne({ identifier }) as Promise<Configuration | null>
|
|
}
|
|
|
|
static async findAllEnabled(sort: Sort = { priority: -1 }): Promise<Configuration[]> {
|
|
const collection = this.getCollection()
|
|
return collection.find({ enabled: true }).sort(sort).toArray() as unknown as Promise<Configuration[]>
|
|
}
|
|
|
|
static async paginateConfigurations(
|
|
page: number,
|
|
perPage: number,
|
|
filter: Filter<any> = {},
|
|
sort: Sort = { priority: -1 }
|
|
): Promise<{ data: Configuration[]; total: number; page: number; perPage: number; lastPage: number }> {
|
|
return this.paginate(page, perPage, filter, sort)
|
|
}
|
|
|
|
static async createIfNotExists(data: Partial<Configuration>): Promise<Configuration> {
|
|
const existing = await this.findOne({ identifier: data.identifier })
|
|
if (existing) {
|
|
throw new Error(`Configuration with identifier '${data.identifier}' already exists`)
|
|
}
|
|
return this.create(data) as Promise<Configuration>
|
|
}
|
|
|
|
static async deleteByIdentifier(identifier: string): Promise<boolean> {
|
|
return this.deleteOne({ identifier })
|
|
}
|
|
}
|