From a2f80374b0e3f6b58ec82b3c9678ef983e8fed84 Mon Sep 17 00:00:00 2001 From: arpitnath Date: Thu, 26 Oct 2023 20:07:22 +0530 Subject: [PATCH] update component dto --- server/src/dto/component.dto.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/server/src/dto/component.dto.ts b/server/src/dto/component.dto.ts index 92ff0a0040..1c12fa8ce5 100644 --- a/server/src/dto/component.dto.ts +++ b/server/src/dto/component.dto.ts @@ -100,6 +100,25 @@ class ComponentDto { parent: string; } +@ValidatorConstraint({ name: 'CreateComponentDtoValidator', async: false }) +class CreateComponentDtoValidator implements ValidatorConstraintInterface { + validate(value: any, args: ValidationArguments) { + // Check if the diff structure is valid + for (const key in value.diff) { + if (!value.diff[key] || typeof value.diff[key] !== 'object') { + return false; + } + // You can add additional checks for the component structure here + } + + return true; + } + + defaultMessage(args: ValidationArguments) { + return `Invalid structure in diff for CreateComponentDto`; + } +} + export class CreateComponentDto { @IsBoolean() is_user_switched_version: boolean; @@ -108,6 +127,7 @@ export class CreateComponentDto { pageId: string; @IsObject() + @Validate(CreateComponentDtoValidator) diff: Record; } @@ -119,6 +139,7 @@ export class UpdateComponentDto { pageId: string; @IsObject() + @Validate(CreateComponentDtoValidator) diff: Record; }