From 23b5e33a6be130b1842a8bf8aaf331ddc350e21c Mon Sep 17 00:00:00 2001 From: ATX Bot Date: Mon, 8 Jun 2026 14:57:41 +0200 Subject: [PATCH] =?UTF-8?q?Implement=20DeviceModel.distinctCriteriaValues(?= =?UTF-8?q?)=20=E2=80=94=20fixes=20500=20on=20/api/v1/devices/criteria-val?= =?UTF-8?q?ues.=20Uses=20MongoDB=20distinct()=20to=20get=20unique=20manufa?= =?UTF-8?q?cturers,=20OUIs,=20productClasses=20from=20devices=20collection?= =?UTF-8?q?.=20Build=20status:=20Success?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/devices_controller.ts | 2 +- app/models/device.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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 = {}