- 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.
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { BaseModel } from '#database/base_model'
|
|
import { type MigrationRoute } from '#domain/firmware/firmware_catalog'
|
|
import { type Sort } from 'mongodb'
|
|
|
|
export default class MigrationRouteModel extends BaseModel {
|
|
static collectionName = 'migration_routes'
|
|
|
|
static async findByIdentifier(identifier: string): Promise<MigrationRoute | null> {
|
|
return (await this.findOne({ identifier })) as Promise<MigrationRoute | null>
|
|
}
|
|
|
|
static async findByProductClass(
|
|
productClass: string,
|
|
sort: Sort = { priority: -1 }
|
|
): Promise<MigrationRoute[]> {
|
|
const collection = this.getCollection()
|
|
return (await collection.find({ productClass }).sort(sort).toArray()) as unknown as Promise<
|
|
MigrationRoute[]
|
|
>
|
|
}
|
|
|
|
static async createIfNotExists(data: Partial<MigrationRoute>): Promise<MigrationRoute> {
|
|
const existing = await this.findOne({ identifier: data.identifier })
|
|
if (existing) {
|
|
throw new Error(`Migration route with identifier '${data.identifier}' already exists`)
|
|
}
|
|
return (await this.create(data)) as Promise<MigrationRoute>
|
|
}
|
|
|
|
static async deleteByIdentifier(identifier: string): Promise<boolean> {
|
|
return this.deleteOne({ identifier })
|
|
}
|
|
}
|