From 43a6663230d5cd7581c35edb3dca3b0c6590db03 Mon Sep 17 00:00:00 2001 From: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Date: Wed, 16 Apr 2025 09:30:29 +0300 Subject: [PATCH] fix: routing form endpoints date filters validation (#20715) --- ...ing-forms-responses.controller.e2e-spec.ts | 5 +++- ...get-routing-form-responses-params.input.ts | 27 ++++--------------- .../organizations-routing-forms.repository.ts | 16 +++++------ ...zations-routing-forms-responses.service.ts | 8 +++--- .../organizations-routing-forms.service.ts | 8 +++--- ...rganizations-teams-routing-forms.module.ts | 1 - ...eams-routing-forms-responses.repository.ts | 4 +-- ...izations-teams-routing-forms.repository.ts | 8 +++--- ...s-teams-routing-forms-responses.service.ts | 8 +++--- ...ganizations-teams-routing-forms.service.ts | 8 +++--- 10 files changed, 39 insertions(+), 54 deletions(-) diff --git a/apps/api/v2/src/modules/organizations/routing-forms/controllers/organizations-routing-forms-responses.controller.e2e-spec.ts b/apps/api/v2/src/modules/organizations/routing-forms/controllers/organizations-routing-forms-responses.controller.e2e-spec.ts index c0061033ce..3001433025 100644 --- a/apps/api/v2/src/modules/organizations/routing-forms/controllers/organizations-routing-forms-responses.controller.e2e-spec.ts +++ b/apps/api/v2/src/modules/organizations/routing-forms/controllers/organizations-routing-forms-responses.controller.e2e-spec.ts @@ -178,9 +178,12 @@ describe("OrganizationsRoutingFormsResponsesController", () => { }); it("should get routing form responses", async () => { + const createdAt = new Date(routingFormResponse.createdAt); + createdAt.setHours(createdAt.getHours() - 1); + const isoStringCreatedAt = createdAt.toISOString(); return request(app.getHttpServer()) .get( - `/v2/organizations/${org.id}/routing-forms/${routingForm.id}/responses?skip=0&take=2&sortUpdatedAt=asc&sortCreatedAt=desc` + `/v2/organizations/${org.id}/routing-forms/${routingForm.id}/responses?skip=0&take=2&sortUpdatedAt=asc&sortCreatedAt=desc&afterCreatedAt=${isoStringCreatedAt}` ) .set({ Authorization: `Bearer cal_test_${apiKeyString}` }) .expect(200) diff --git a/apps/api/v2/src/modules/organizations/routing-forms/inputs/get-routing-form-responses-params.input.ts b/apps/api/v2/src/modules/organizations/routing-forms/inputs/get-routing-form-responses-params.input.ts index 48edda884d..3b210e0659 100644 --- a/apps/api/v2/src/modules/organizations/routing-forms/inputs/get-routing-form-responses-params.input.ts +++ b/apps/api/v2/src/modules/organizations/routing-forms/inputs/get-routing-form-responses-params.input.ts @@ -1,15 +1,6 @@ import { ApiPropertyOptional } from "@nestjs/swagger"; import { Transform } from "class-transformer"; -import { - IsOptional, - IsString, - IsEnum, - IsISO8601, - IsDate, - IsNumber, - IsArray, - ArrayMinSize, -} from "class-validator"; +import { IsOptional, IsString, IsEnum, IsISO8601, IsNumber, IsArray, ArrayMinSize } from "class-validator"; enum SortOrder { ASC = "asc", @@ -44,9 +35,7 @@ export class GetRoutingFormResponsesParams { }) @IsOptional() @IsISO8601() - @Transform(({ value }) => value && new Date(value)) - @IsDate() - afterCreatedAt?: Date; + afterCreatedAt?: string; @ApiPropertyOptional({ type: String, @@ -55,9 +44,7 @@ export class GetRoutingFormResponsesParams { }) @IsOptional() @IsISO8601() - @Transform(({ value }) => value && new Date(value)) - @IsDate() - beforeCreatedAt?: Date; + beforeCreatedAt?: string; @ApiPropertyOptional({ type: String, @@ -66,9 +53,7 @@ export class GetRoutingFormResponsesParams { }) @IsOptional() @IsISO8601() - @Transform(({ value }) => value && new Date(value)) - @IsDate() - afterUpdatedAt?: Date; + afterUpdatedAt?: string; @ApiPropertyOptional({ type: String, @@ -77,9 +62,7 @@ export class GetRoutingFormResponsesParams { }) @IsOptional() @IsISO8601() - @Transform(({ value }) => value && new Date(value)) - @IsDate() - beforeUpdatedAt?: Date; + beforeUpdatedAt?: string; @ApiPropertyOptional({ type: String, description: "Filter by responses routed to a specific booking" }) @IsOptional() diff --git a/apps/api/v2/src/modules/organizations/routing-forms/organizations-routing-forms.repository.ts b/apps/api/v2/src/modules/organizations/routing-forms/organizations-routing-forms.repository.ts index 251cc341a5..66fe05d83f 100644 --- a/apps/api/v2/src/modules/organizations/routing-forms/organizations-routing-forms.repository.ts +++ b/apps/api/v2/src/modules/organizations/routing-forms/organizations-routing-forms.repository.ts @@ -15,10 +15,10 @@ export class OrganizationsRoutingFormsRepository { name?: string; sortCreatedAt?: "asc" | "desc"; sortUpdatedAt?: "asc" | "desc"; - afterCreatedAt?: Date; - beforeCreatedAt?: Date; - afterUpdatedAt?: Date; - beforeUpdatedAt?: Date; + afterCreatedAt?: string; + beforeCreatedAt?: string; + afterUpdatedAt?: string; + beforeUpdatedAt?: string; teamIds?: number[]; } ) { @@ -61,10 +61,10 @@ export class OrganizationsRoutingFormsRepository { options?: { sortCreatedAt?: "asc" | "desc"; sortUpdatedAt?: "asc" | "desc"; - afterCreatedAt?: Date; - beforeCreatedAt?: Date; - afterUpdatedAt?: Date; - beforeUpdatedAt?: Date; + afterCreatedAt?: string; + beforeCreatedAt?: string; + afterUpdatedAt?: string; + beforeUpdatedAt?: string; routedToBookingUid?: string; } ) { diff --git a/apps/api/v2/src/modules/organizations/routing-forms/services/organizations-routing-forms-responses.service.ts b/apps/api/v2/src/modules/organizations/routing-forms/services/organizations-routing-forms-responses.service.ts index a4a668fa17..33a612604e 100644 --- a/apps/api/v2/src/modules/organizations/routing-forms/services/organizations-routing-forms-responses.service.ts +++ b/apps/api/v2/src/modules/organizations/routing-forms/services/organizations-routing-forms-responses.service.ts @@ -17,10 +17,10 @@ export class OrganizationsRoutingFormsResponsesService { options?: { sortCreatedAt?: "asc" | "desc"; sortUpdatedAt?: "asc" | "desc"; - afterCreatedAt?: Date; - beforeCreatedAt?: Date; - afterUpdatedAt?: Date; - beforeUpdatedAt?: Date; + afterCreatedAt?: string; + beforeCreatedAt?: string; + afterUpdatedAt?: string; + beforeUpdatedAt?: string; routedToBookingUid?: string; } ) { diff --git a/apps/api/v2/src/modules/organizations/routing-forms/services/organizations-routing-forms.service.ts b/apps/api/v2/src/modules/organizations/routing-forms/services/organizations-routing-forms.service.ts index eab3330261..97e178d8a5 100644 --- a/apps/api/v2/src/modules/organizations/routing-forms/services/organizations-routing-forms.service.ts +++ b/apps/api/v2/src/modules/organizations/routing-forms/services/organizations-routing-forms.service.ts @@ -14,10 +14,10 @@ export class OrganizationsRoutingFormsService { name?: string; sortCreatedAt?: "asc" | "desc"; sortUpdatedAt?: "asc" | "desc"; - afterCreatedAt?: Date; - beforeCreatedAt?: Date; - afterUpdatedAt?: Date; - beforeUpdatedAt?: Date; + afterCreatedAt?: string; + beforeCreatedAt?: string; + afterUpdatedAt?: string; + beforeUpdatedAt?: string; teamIds?: number[]; } ) { diff --git a/apps/api/v2/src/modules/organizations/teams/routing-forms/organizations-teams-routing-forms.module.ts b/apps/api/v2/src/modules/organizations/teams/routing-forms/organizations-teams-routing-forms.module.ts index e6b5ac672e..be2bb9c2f2 100644 --- a/apps/api/v2/src/modules/organizations/teams/routing-forms/organizations-teams-routing-forms.module.ts +++ b/apps/api/v2/src/modules/organizations/teams/routing-forms/organizations-teams-routing-forms.module.ts @@ -5,7 +5,6 @@ import { OrganizationsRoutingFormsResponsesService } from "@/modules/organizatio import { OrganizationsTeamsRepository } from "@/modules/organizations/teams/index/organizations-teams.repository"; import { PrismaModule } from "@/modules/prisma/prisma.module"; import { RedisModule } from "@/modules/redis/redis.module"; -import { RedisService } from "@/modules/redis/redis.service"; import { RoutingFormsModule } from "@/modules/routing-forms/routing-forms.module"; import { StripeModule } from "@/modules/stripe/stripe.module"; import { Module } from "@nestjs/common"; diff --git a/apps/api/v2/src/modules/organizations/teams/routing-forms/repositories/organizations-teams-routing-forms-responses.repository.ts b/apps/api/v2/src/modules/organizations/teams/routing-forms/repositories/organizations-teams-routing-forms-responses.repository.ts index 8b466e7b73..ac288fa903 100644 --- a/apps/api/v2/src/modules/organizations/teams/routing-forms/repositories/organizations-teams-routing-forms-responses.repository.ts +++ b/apps/api/v2/src/modules/organizations/teams/routing-forms/repositories/organizations-teams-routing-forms-responses.repository.ts @@ -13,8 +13,8 @@ export class OrganizationsTeamsRoutingFormsResponsesRepository { take: number, options?: { sortCreatedAt?: "asc" | "desc"; - afterCreatedAt?: Date; - beforeCreatedAt?: Date; + afterCreatedAt?: string; + beforeCreatedAt?: string; routedToBookingUid?: string; } ) { diff --git a/apps/api/v2/src/modules/organizations/teams/routing-forms/repositories/organizations-teams-routing-forms.repository.ts b/apps/api/v2/src/modules/organizations/teams/routing-forms/repositories/organizations-teams-routing-forms.repository.ts index 7645ff04eb..1386173222 100644 --- a/apps/api/v2/src/modules/organizations/teams/routing-forms/repositories/organizations-teams-routing-forms.repository.ts +++ b/apps/api/v2/src/modules/organizations/teams/routing-forms/repositories/organizations-teams-routing-forms.repository.ts @@ -15,10 +15,10 @@ export class OrganizationsTeamsRoutingFormsRepository { name?: string; sortCreatedAt?: "asc" | "desc"; sortUpdatedAt?: "asc" | "desc"; - afterCreatedAt?: Date; - beforeCreatedAt?: Date; - afterUpdatedAt?: Date; - beforeUpdatedAt?: Date; + afterCreatedAt?: string; + beforeCreatedAt?: string; + afterUpdatedAt?: string; + beforeUpdatedAt?: string; } ) { const { diff --git a/apps/api/v2/src/modules/organizations/teams/routing-forms/services/organizations-teams-routing-forms-responses.service.ts b/apps/api/v2/src/modules/organizations/teams/routing-forms/services/organizations-teams-routing-forms-responses.service.ts index 9bca5f1d0f..aa57d287ba 100644 --- a/apps/api/v2/src/modules/organizations/teams/routing-forms/services/organizations-teams-routing-forms-responses.service.ts +++ b/apps/api/v2/src/modules/organizations/teams/routing-forms/services/organizations-teams-routing-forms-responses.service.ts @@ -18,10 +18,10 @@ export class OrganizationsTeamsRoutingFormsResponsesService { options?: { sortCreatedAt?: "asc" | "desc"; sortUpdatedAt?: "asc" | "desc"; - afterCreatedAt?: Date; - beforeCreatedAt?: Date; - afterUpdatedAt?: Date; - beforeUpdatedAt?: Date; + afterCreatedAt?: string; + beforeCreatedAt?: string; + afterUpdatedAt?: string; + beforeUpdatedAt?: string; routedToBookingUid?: string; } ) { diff --git a/apps/api/v2/src/modules/organizations/teams/routing-forms/services/organizations-teams-routing-forms.service.ts b/apps/api/v2/src/modules/organizations/teams/routing-forms/services/organizations-teams-routing-forms.service.ts index 5eae271654..920ec28946 100644 --- a/apps/api/v2/src/modules/organizations/teams/routing-forms/services/organizations-teams-routing-forms.service.ts +++ b/apps/api/v2/src/modules/organizations/teams/routing-forms/services/organizations-teams-routing-forms.service.ts @@ -15,10 +15,10 @@ export class OrganizationsTeamsRoutingFormsService { name?: string; sortCreatedAt?: "asc" | "desc"; sortUpdatedAt?: "asc" | "desc"; - afterCreatedAt?: Date; - beforeCreatedAt?: Date; - afterUpdatedAt?: Date; - beforeUpdatedAt?: Date; + afterCreatedAt?: string; + beforeCreatedAt?: string; + afterUpdatedAt?: string; + beforeUpdatedAt?: string; } ) { return this.routingFormsRepository.getTeamRoutingForms(teamId, skip, take, options);