Skip to content

Commit 73764ff

Browse files
committed
better type validation
1 parent d4b6ecd commit 73764ff

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

backend/apps/cloud/src/experiment/experiment.controller.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
AnalyticsService,
3939
getLowestPossibleTimeBucket,
4040
} from '../analytics/analytics.service'
41+
import { TimeBucketType } from '../analytics/dto/getData.dto'
4142
import { Auth } from '../auth/decorators'
4243
import { CurrentUserId } from '../auth/decorators/current-user-id.decorator'
4344
import { checkRateLimit, getIPFromHeaders } from '../common/utils'
@@ -790,7 +791,7 @@ export class ExperimentController {
790791
@CurrentUserId() userId: string,
791792
@Param('id') id: string,
792793
@Query('period') period: string,
793-
@Query('timeBucket') timeBucketParam?: string,
794+
@Query('timeBucket') timeBucketParam?: TimeBucketType,
794795
@Query('from') from?: string,
795796
@Query('to') to?: string,
796797
@Query('timezone') timezone?: string,
@@ -815,7 +816,7 @@ export class ExperimentController {
815816

816817
let timeBucket =
817818
timeBucketParam || getLowestPossibleTimeBucket(period, from, to)
818-
let allowedTimeBucketForPeriodAll: string[] | undefined
819+
let allowedTimeBucketForPeriodAll: TimeBucketType[] | undefined
819820
let diff: number | undefined
820821

821822
if (period === 'all') {
@@ -826,7 +827,7 @@ export class ExperimentController {
826827

827828
diff = res.diff
828829

829-
timeBucket = res.timeBucket.includes(timeBucket as any)
830+
timeBucket = res.timeBucket.includes(timeBucket)
830831
? timeBucket
831832
: res.timeBucket[0]
832833
allowedTimeBucketForPeriodAll = res.timeBucket
@@ -836,7 +837,7 @@ export class ExperimentController {
836837
this.analyticsService.getGroupFromTo(
837838
from,
838839
to,
839-
timeBucket as any,
840+
timeBucket,
840841
period,
841842
safeTimezone,
842843
diff,
@@ -1015,7 +1016,7 @@ export class ExperimentController {
10151016
try {
10161017
chart = await this.generateExperimentChart(
10171018
experiment,
1018-
timeBucket as any,
1019+
timeBucket,
10191020
groupFrom,
10201021
groupTo,
10211022
groupFromUTC,
@@ -1046,15 +1047,15 @@ export class ExperimentController {
10461047
*/
10471048
private async generateExperimentChart(
10481049
experiment: Experiment,
1049-
timeBucket: string,
1050+
timeBucket: TimeBucketType,
10501051
groupFrom: string,
10511052
groupTo: string,
10521053
groupFromUTC: string,
10531054
groupToUTC: string,
10541055
safeTimezone: string,
10551056
): Promise<{ x: string[]; winProbability: Record<string, number[]> }> {
10561057
const { xShifted } = this.analyticsService.generateXAxis(
1057-
timeBucket as any,
1058+
timeBucket,
10581059
groupFrom,
10591060
groupTo,
10601061
safeTimezone,

backend/apps/cloud/src/revenue/dto/get-revenue.dto.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import {
66
IsInt,
77
Min,
88
Max,
9+
IsEnum,
910
} from 'class-validator'
1011
import { Type } from 'class-transformer'
12+
import { TimeBucketType } from '../../analytics/dto/getData.dto'
1113

1214
export class GetRevenueDto {
1315
@ApiProperty({ description: 'Project ID' })
@@ -35,10 +37,13 @@ export class GetRevenueDto {
3537
@IsString()
3638
timezone?: string
3739

38-
@ApiPropertyOptional({ description: 'Time bucket for chart data' })
40+
@ApiPropertyOptional({
41+
description: 'Time bucket for chart data',
42+
enum: TimeBucketType,
43+
})
3944
@IsOptional()
40-
@IsString()
41-
timeBucket?: string
45+
@IsEnum(TimeBucketType)
46+
timeBucket?: TimeBucketType
4247
}
4348

4449
export class GetRevenueTransactionsDto extends GetRevenueDto {

backend/apps/cloud/src/revenue/revenue.controller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,13 @@ export class RevenueAnalyticsController {
301301
const { groupFromUTC, groupToUTC } = this.analyticsService.getGroupFromTo(
302302
dto.from,
303303
dto.to,
304-
timeBucket as any,
304+
timeBucket,
305305
dto.period,
306306
safeTimezone,
307307
)
308308

309309
const { xShifted } = this.analyticsService.generateXAxis(
310-
timeBucket as any,
310+
timeBucket,
311311
groupFromUTC,
312312
groupToUTC,
313313
safeTimezone,
@@ -365,7 +365,7 @@ export class RevenueAnalyticsController {
365365
const { groupFromUTC, groupToUTC } = this.analyticsService.getGroupFromTo(
366366
dto.from,
367367
dto.to,
368-
timeBucket as any,
368+
timeBucket,
369369
dto.period,
370370
safeTimezone,
371371
)
@@ -411,7 +411,7 @@ export class RevenueAnalyticsController {
411411
const { groupFromUTC, groupToUTC } = this.analyticsService.getGroupFromTo(
412412
dto.from,
413413
dto.to,
414-
timeBucket as any,
414+
timeBucket,
415415
dto.period,
416416
safeTimezone,
417417
)

0 commit comments

Comments
 (0)