From f73f2463ed9e49044030b01fa03f730a425a01b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Dislay?= Date: Thu, 22 Jun 2023 17:30:56 +0200 Subject: [PATCH] feat(createGroup): id is not mandatory anymore, auto generated if missing --- lib/modules/asset/AssetsGroupsController.ts | 22 ++++++++++++--------- lib/modules/asset/types/AssetGroupsApi.ts | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/modules/asset/AssetsGroupsController.ts b/lib/modules/asset/AssetsGroupsController.ts index 5b59d6e3..c2968e4f 100644 --- a/lib/modules/asset/AssetsGroupsController.ts +++ b/lib/modules/asset/AssetsGroupsController.ts @@ -3,27 +3,28 @@ import { ControllerDefinition, EmbeddedSDK, KuzzleRequest, + NameGenerator, User, } from "kuzzle"; import { DeviceManagerPlugin, InternalCollection } from "../plugin"; +import { AssetContent } from "./exports"; +import { + AssetsGroupContent, + AssetsGroupsBody, +} from "./types/AssetGroupContent"; import { - AssetsGroupsBodyRequest, ApiGroupAddAssetsRequest, ApiGroupAddAssetsResult, ApiGroupCreateResult, ApiGroupDeleteResult, ApiGroupGetResult, + ApiGroupRemoveAssetsRequest, + ApiGroupRemoveAssetsResult, ApiGroupSearchResult, ApiGroupUpdateResult, - ApiGroupRemoveAssetsResult, - ApiGroupRemoveAssetsRequest, + AssetsGroupsBodyRequest, } from "./types/AssetGroupsApi"; -import { - AssetsGroupsBody, - AssetsGroupContent, -} from "./types/AssetGroupContent"; -import { AssetContent } from "./exports"; export class AssetsGroupsController { definition: ControllerDefinition; @@ -161,7 +162,10 @@ export class AssetsGroupsController { async create(request: KuzzleRequest): Promise { const engineId = request.getString("engineId"); - const _id = request.getId(); + const _id = request.getId({ + generator: () => NameGenerator.generateRandomName({ prefix: "group" }), + ifMissing: "generate", + }); const body = request.getBody() as AssetsGroupsBodyRequest; await this.checkParent(engineId, body); diff --git a/lib/modules/asset/types/AssetGroupsApi.ts b/lib/modules/asset/types/AssetGroupsApi.ts index 29641a37..dcb7cf60 100644 --- a/lib/modules/asset/types/AssetGroupsApi.ts +++ b/lib/modules/asset/types/AssetGroupsApi.ts @@ -18,7 +18,7 @@ interface GroupControllerRequest { export interface ApiGroupCreateRequest extends GroupControllerRequest { action: "create"; - _id: string; + _id?: string; body: Omit; }