- 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.
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { BaseModel } from '#database/base_model'
|
|
import { type Configuration } from '#domain/configuration/configuration'
|
|
import { type Filter, type 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 (await 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 (await this.create(data)) as Configuration
|
|
}
|
|
|
|
static async distinctTags(): Promise<string[]> {
|
|
const collection = this.getCollection()
|
|
const tags = await collection.distinct('tags')
|
|
return (tags as string[]).filter(Boolean).sort()
|
|
}
|
|
|
|
static async deleteByIdentifier(identifier: string): Promise<boolean> {
|
|
return this.deleteOne({ identifier })
|
|
}
|
|
}
|