diff --git a/docs/swagger.yaml b/docs/swagger.yaml index b030495..b2b1ddd 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -462,6 +462,12 @@ paths: - Device description: | List distinct device models. + parameters: + - name: type + in: query + description: Filter by device type, case insensitive, partial match is used + required: false + type: string responses: '200': diff --git a/src/controllers/DeviceController.js b/src/controllers/DeviceController.js index 0077316..f540b57 100644 --- a/src/controllers/DeviceController.js +++ b/src/controllers/DeviceController.js @@ -113,7 +113,7 @@ async function getManufacturers (req, res) { * @param {Object} res the response */ async function getDeviceModels (req, res) { - const result = await service.getDeviceModels() + const result = await service.getDeviceModels(req.query) res.send(result) } diff --git a/src/services/DeviceService.js b/src/services/DeviceService.js index 05e4ae1..38fd3d0 100644 --- a/src/services/DeviceService.js +++ b/src/services/DeviceService.js @@ -353,11 +353,12 @@ getManufacturers.schema = { /** * Get distinct device models. + * @param {Object} criteria the search criteria * @returns {Array} the distinct device models */ -async function getDeviceModels () { +async function getDeviceModels (criteria) { const result = [] - await iterateDevices({}, (device) => { + await iterateDevices(criteria, (device) => { if (!_.includes(result, device.model)) { result.push(device.model) } @@ -365,6 +366,12 @@ async function getDeviceModels () { return result } +getDeviceModels.schema = { + criteria: Joi.object().keys({ + type: Joi.string() + }) +} + module.exports = { list, getEntity,