Skip to content

Commit

Permalink
fix(AssetController): pass options to search query (#224)
Browse files Browse the repository at this point in the history
* fix(AssetController): pass options to search query
fix #223
Up the version in 2.0.0-rc23
  • Loading branch information
sebtiz13 committed Sep 22, 2022
1 parent 91a1005 commit d220132
Show file tree
Hide file tree
Showing 4 changed files with 332 additions and 743 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" |
Then I refresh the collection "engine-kuzzle":"assets"
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 "hits" array of objects matching:
| _id | _source.model |
| "outils-PERFO-asset_01" | "PERFO" |
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
Loading

0 comments on commit d220132

Please sign in to comment.