Skip to content
Advertisement

How to create dto of an complex object in NestJs

I’m a beginner at NestJs and I want to create a dto of the following struct:

I want to create an API that can return this object using DTOs.

JavaScript

I tried the following dto but I got an error in the service provider :

I create 3 classes OneSessionResponseDto, SessionsResponseDto, and WeekResponseDto so I can use them as a dto of the object above.

JavaScript

this is the service provider class:

JavaScript

I got this error here:

is missing the following properties from type ‘SessionsResponseDto’: First, Second, Third

Advertisement

Answer

You almost have it. You need to set TimeZone‘s type to SessionsResponseDto[] because it’s an array. Then change OneSessionResponseDto#start to OneSessionResponseDto#Start (the capitalization is important). You can see a working solution in the typoescript playground here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement