From 77d269cbc1d176c32bc91f61d02c061f6d4b6d98 Mon Sep 17 00:00:00 2001 From: CapoMK25 Date: Wed, 22 Jul 2026 17:00:47 +0300 Subject: [PATCH] Addressed the legacy Avatar situation with Transform --- src/player/dto/avatar.dto.ts | 22 +++++++++++----------- src/player/schemas/avatar.schema.ts | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/player/dto/avatar.dto.ts b/src/player/dto/avatar.dto.ts index 5db0133d..188d200b 100644 --- a/src/player/dto/avatar.dto.ts +++ b/src/player/dto/avatar.dto.ts @@ -1,4 +1,4 @@ -import { Expose, Type } from 'class-transformer'; +import { Expose, Type, Transform } from 'class-transformer'; import { IsNumber, IsHexColor, ValidateNested } from 'class-validator'; export class AvatarPieceDto { @@ -28,8 +28,8 @@ export class AvatarDto { * Configuration for the avatar's head shape and base. * @example {AvatarPieceDto} */ - @Expose() + @Transform(({ value }) => (typeof value === 'number' ? { id: value, color: '#ffffff' } : value)) @ValidateNested() @Type(() => AvatarPieceDto) head: AvatarPieceDto; @@ -38,8 +38,8 @@ export class AvatarDto { * Configuration for the avatar's hairstyle and color. * @type {AvatarPieceDto} */ - @Expose() + @Transform(({ value }) => (typeof value === 'number' ? { id: value, color: '#ffffff' } : value)) @ValidateNested() @Type(() => AvatarPieceDto) hair: AvatarPieceDto; @@ -48,8 +48,8 @@ export class AvatarDto { * Configuration for the avatar's eye shape and iris color. * @type {AvatarPieceDto} */ - @Expose() + @Transform(({ value }) => (typeof value === 'number' ? { id: value, color: '#ffffff' } : value)) @ValidateNested() @Type(() => AvatarPieceDto) eyes: AvatarPieceDto; @@ -58,8 +58,8 @@ export class AvatarDto { * Configuration for the avatar's nose structure. * @type {AvatarPieceDto} */ - @Expose() + @Transform(({ value }) => (typeof value === 'number' ? { id: value, color: '#ffffff' } : value)) @ValidateNested() @Type(() => AvatarPieceDto) nose: AvatarPieceDto; @@ -68,8 +68,8 @@ export class AvatarDto { * Configuration for the avatar's mouth and lip shape. * @type {AvatarPieceDto} */ - @Expose() + @Transform(({ value }) => (typeof value === 'number' ? { id: value, color: '#ffffff' } : value)) @ValidateNested() @Type(() => AvatarPieceDto) mouth: AvatarPieceDto; @@ -78,8 +78,8 @@ export class AvatarDto { * Configuration for the avatar's eyebrow shape and thickness. * @type {AvatarPieceDto} */ - @Expose() + @Transform(({ value }) => (typeof value === 'number' ? { id: value, color: '#ffffff' } : value)) @ValidateNested() @Type(() => AvatarPieceDto) eyebrows: AvatarPieceDto; @@ -88,8 +88,8 @@ export class AvatarDto { * Configuration for the avatar's upper body clothing or outfit. * @type {AvatarPieceDto} */ - @Expose() + @Transform(({ value }) => (typeof value === 'number' ? { id: value, color: '#ffffff' } : value)) @ValidateNested() @Type(() => AvatarPieceDto) clothes: AvatarPieceDto; @@ -98,8 +98,8 @@ export class AvatarDto { * Configuration for the avatar's footwear. * @type {AvatarPieceDto} */ - @Expose() + @Transform(({ value }) => (typeof value === 'number' ? { id: value, color: '#ffffff' } : value)) @ValidateNested() @Type(() => AvatarPieceDto) feet: AvatarPieceDto; @@ -108,8 +108,8 @@ export class AvatarDto { * Configuration for the avatar's hand features or gloves. * @type {AvatarPieceDto} */ - @Expose() + @Transform(({ value }) => (typeof value === 'number' ? { id: value, color: '#ffffff' } : value)) @ValidateNested() @Type(() => AvatarPieceDto) hands: AvatarPieceDto; @@ -121,4 +121,4 @@ export class AvatarDto { @Expose() @IsHexColor() skinColor: string; -} +} \ No newline at end of file diff --git a/src/player/schemas/avatar.schema.ts b/src/player/schemas/avatar.schema.ts index 6c9bbe94..513cc222 100644 --- a/src/player/schemas/avatar.schema.ts +++ b/src/player/schemas/avatar.schema.ts @@ -52,4 +52,4 @@ export class Avatar { skinColor: string; } -export const AvatarSchema = SchemaFactory.createForClass(Avatar); +export const AvatarSchema = SchemaFactory.createForClass(Avatar); \ No newline at end of file