Skip to content

Commit

Permalink
fix(AssetController): pass options to search query
Browse files Browse the repository at this point in the history
  • Loading branch information
sebtiz13 committed Sep 21, 2022
1 parent 91a1005 commit f2bce6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
13 changes: 11 additions & 2 deletions features/AssetController.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ Feature: DeviceManager asset controller
| model | "PERFO" |
| metadata.foobar | 42 |
| metadata.index | "engine-kuzzle" |
When I successfully execute the action "device-manager/asset":"search" with args:
| engineId | "engine-kuzzle" |
| body | {"query":{"equals":{"_id":"outils-PERFO-asset_01"}}} |
| size | "1" |
| lang | "koncorde" |
Then I should receive a result matching:
| model | "PERFO" |
| metadata.foobar | 42 |
| metadata.index | "engine-kuzzle" |
When I successfully execute the action "device-manager/asset":"delete" with args:
| engineId | "engine-kuzzle" |
| _id | "outils-PERFO-asset_01" |
Expand Down Expand Up @@ -140,7 +149,7 @@ Feature: DeviceManager asset controller
| measures[0].values.battery | 90 |
| measures[1].assetMeasureName | "leftOuterTemp" |
| measures[1].values.temperature | 30 |
| measures[2].assetMeasureName | "leftInnerTemp" |
| measures[2].assetMeasureName | "leftInnerTemp" |
| measures[2].values.temperature | -10 |
| measures[3].assetMeasureName | "rightOuterTemp" |
| measures[3].values.temperature | 40 |
Expand All @@ -163,7 +172,7 @@ Feature: DeviceManager asset controller
| measures[0].values.battery | 90 |
| measures[1].assetMeasureName | "leftOuterTemp" |
| measures[1].values.temperature | 31 |
| measures[2].assetMeasureName | "leftInnerTemp" |
| measures[2].assetMeasureName | "leftInnerTemp" |
| measures[2].values.temperature | -10 |
| measures[3].assetMeasureName | "rightOuterTemp" |
| measures[3].values.temperature | 40 |
Expand Down
16 changes: 13 additions & 3 deletions lib/controllers/AssetController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export class AssetController extends RelationalController {
const updatedMetadata = this.assetCategoryService.formatMetadataForES(assetMetadata);
request.input.body.metadata = [...updatedMetadata, ...previousMetadata];
}

const response = await global.app.trigger(
'device-manager:asset:update:before', {
asset,
Expand Down Expand Up @@ -300,10 +300,20 @@ export class AssetController extends RelationalController {
*/
async search (request: KuzzleRequest) {
const engineId = request.getString('engineId');
const { searchBody } = request.getSearchParams();
const { searchBody, from, size, scrollTTL: scroll } = request.getSearchParams();
const category = this.getFieldPath(request, 'category', null, 'asset-category');

const res = await this.sdk.document.search<BaseAssetContent>(engineId, this.collection, searchBody);
const res = await this.sdk.document.search<BaseAssetContent>(
engineId,
this.collection,
searchBody,
{
from,
lang: request.getLangParam(),
scroll,
size,
}
);
for (const hit of res.hits) {
const document = await this.esDocumentToFormatted<BaseAssetContent>(engineId, this.collection, hit, [category]);
this.assetCategoryService.formatDocumentMetadata(document);
Expand Down

0 comments on commit f2bce6e

Please sign in to comment.