Struggling to get the nested object to display in my console log for the past day. Here's the JSON I'm working with:
{
"data": {
"assets": [
{
"asset_name": "Image1.jpg",
"asset_type": "photo",
"is_featured": true,
"asset_id": "alksjd78987120-kjahsdkjahsd61238-kjahsdkjahsjkdh",
"action": "delete"
},
{
"asset_name": "Image2.jpg",
"asset_type": "photo",
"action": "add"
}
]
}
}
Attempting to display console.log(data.assets);
from my controller file, but encountering the error
Property 'assets' does not exist on type 'DataDto'.
Here is my DataDto.ts:
export class CreateAssetsDto {
@IsString()
@IsOptional()
asset_id: string;
... (skipping rest of the code for brevity) ...
export class DataDto {
@ValidateNested()
@Type(() => AssetsArrayDto)
data: AssetsArrayDto;
}
Examining this snippet from my controller.ts:
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
@UsePipes(new ValidationPipe({ transform: true }))
@Put(':id')
async uploadAssets(
@Request() req,
@Param('id') campaignId: string,
@Body() data: DataDto) {
try {
console.log("Data Check");
... (skipping logging and parsing code) ...
return {
statusCode: HttpStatus.OK,
message: data,
};
} catch (error) {
Logger.log('Validation Error: ');
Logger.log(error);
throw new BadRequestException(error);
}
}
}
Am I missing something here? It appears that assets are not being read as part of my data object despite being defined in the DTO.
When I do console.log(data)
, the output is:
Data Check
DataDto {
data: AssetsArrayDto { assets: [ [CreateAssetsDto], [CreateAssetsDto] ] }
}