diff --git a/app/controllers/devices_controller.ts b/app/controllers/devices_controller.ts index a64c2f0..84a75e1 100644 --- a/app/controllers/devices_controller.ts +++ b/app/controllers/devices_controller.ts @@ -8,7 +8,7 @@ export default class DevicesController { private deviceService = new DeviceService() async criteriaValues({ response }: HttpContext) { - const values = await (DeviceModel as any).distinctCriteriaValues() + const values = await DeviceModel.distinctCriteriaValues() return response.json(values) } diff --git a/app/models/device.ts b/app/models/device.ts index c6c6e02..9708ea5 100644 --- a/app/models/device.ts +++ b/app/models/device.ts @@ -38,6 +38,24 @@ export default class DeviceModel extends BaseModel { return { data, total } } + static async distinctCriteriaValues(): Promise<{ + manufacturers: string[] + ouis: string[] + productClasses: string[] + }> { + const collection = this.getCollection() + const [manufacturers, ouis, productClasses] = await Promise.all([ + collection.distinct('deviceId.manufacturer'), + collection.distinct('deviceId.oui'), + collection.distinct('deviceId.productClass'), + ]) + return { + manufacturers: manufacturers.filter((v: any) => v && typeof v === 'string').sort(), + ouis: ouis.filter((v: any) => v && typeof v === 'string').sort(), + productClasses: productClasses.filter((v: any) => v && typeof v === 'string').sort(), + } + } + static async createOrUpdate(device: Partial): Promise { const collection = this.getCollection() let filter: Filter = {}