Currently, I am setting up a query with the following structure for my GET endpoint:
export class AnalyticsRequestDTO<
G extends GroupableKeys,
P extends PopulateableKeys<G> | undefined = undefined
>
implements AggregateRunLogAnalyticsOptions<G, P>
{
@IsObject()
@IsOptional()
@ApiProperty({
description: 'Filters to apply logs',
required: false,
})
filter: AnalyticsFilterDTO = {}
@IsArray()
@ApiProperty({
description: 'The fields to group by',
required: false,
})
groupBy: G[]
@IsArray()
@IsOptional()
@ApiProperty({
description: 'The fields to populate',
type: [String],
required: false,
})
populate?: P[]
}
The issue lies in the fact that the AnalyticsFilterDTO
is being spread. I want to prevent this behavior as it causes failures when the query is not wrapped properly. Here's the complete controller code:
@Get('/app/:appId/pages')
public async getPageRuleStatistics<G extends GroupableKeys>(
@Param('appId', MongoIdPipe) applicationId: string,
@Query() query: AnalyticsRequestDTO<G>,
@Query('forceRebuild', new DefaultValuePipe(false), ParseBoolPipe)
forceRebuild = false
): Promise<AnalyticsResultsDTO<G>> {
//Implementation details here...
}
To address this issue, modifications need to be made to the DTO structure. Any suggestions on how to go about this?