mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-24 20:14:35 -04:00
fix: ensure nested objects are properly validated & transformed
To validate nested objects, class-transformer requires the `@ValidateNested` annotation. For arrays, class-transfomer requires setting `each: true`. To correctly transform nested objects from JSON to instances, class-transformer requires the `@Type` annotation. References: https://github.com/typestack/class-validator#validating-nested-objects https://github.com/typestack/class-validator#validating-arrays https://github.com/typestack/class-transformer#working-with-nested-objects Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
324536bc2d
commit
59a235ebc4
3 changed files with 16 additions and 7 deletions
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
|
@ -96,16 +97,18 @@ export class NotePermissionsDto {
|
|||
/**
|
||||
* List of users the note is shared with
|
||||
*/
|
||||
@ValidateNested()
|
||||
@ValidateNested({ each: true })
|
||||
@IsArray()
|
||||
@Type(() => NoteUserPermissionEntryDto)
|
||||
@ApiProperty({ isArray: true, type: NoteUserPermissionEntryDto })
|
||||
sharedToUsers: NoteUserPermissionEntryDto[];
|
||||
|
||||
/**
|
||||
* List of groups the note is shared with
|
||||
*/
|
||||
@ValidateNested()
|
||||
@ValidateNested({ each: true })
|
||||
@IsArray()
|
||||
@Type(() => NoteGroupPermissionEntryDto)
|
||||
@ApiProperty({ isArray: true, type: NoteGroupPermissionEntryDto })
|
||||
sharedToGroups: NoteGroupPermissionEntryDto[];
|
||||
}
|
||||
|
@ -115,7 +118,8 @@ export class NotePermissionsUpdateDto {
|
|||
* List of users the note should be shared with
|
||||
*/
|
||||
@IsArray()
|
||||
@ValidateNested()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => NoteUserPermissionUpdateDto)
|
||||
@ApiProperty({ isArray: true, type: NoteUserPermissionUpdateDto })
|
||||
sharedToUsers: NoteUserPermissionUpdateDto[];
|
||||
|
||||
|
@ -123,7 +127,8 @@ export class NotePermissionsUpdateDto {
|
|||
* List of groups the note should be shared with
|
||||
*/
|
||||
@IsArray()
|
||||
@ValidateNested()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => NoteGroupPermissionUpdateDto)
|
||||
@ApiProperty({ isArray: true, type: NoteGroupPermissionUpdateDto })
|
||||
sharedToGroups: NoteGroupPermissionUpdateDto[];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue