Skip to content

Commit

Permalink
feat(createGroup): id is not mandatory anymore, auto generated if mis…
Browse files Browse the repository at this point in the history
…sing
  • Loading branch information
tdislay committed Jun 22, 2023
1 parent 5861164 commit f73f246
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions lib/modules/asset/AssetsGroupsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -161,7 +162,10 @@ export class AssetsGroupsController {

async create(request: KuzzleRequest): Promise<ApiGroupCreateResult> {
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);
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/asset/types/AssetGroupsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface GroupControllerRequest {

export interface ApiGroupCreateRequest extends GroupControllerRequest {
action: "create";
_id: string;
_id?: string;
body: Omit<AssetsGroupsBodyRequest, "children">;
}

Expand Down

0 comments on commit f73f246

Please sign in to comment.