From 2d3c932aa884c6ed701bc78fd6ffb50a00f9d4b2 Mon Sep 17 00:00:00 2001 From: hannah-macdonald1 Date: Thu, 21 Nov 2024 11:53:50 -0700 Subject: [PATCH 1/2] updating limits and swagger for the post request --- src/common/constants/parameter-constants.ts | 4 +++- src/common/constants/upstream-constants.ts | 4 ++++ src/dto/filter-query-params.dto.ts | 3 ++- src/dto/id-path-params.dto.ts | 8 +++++++- src/dto/post-in-person-visit.dto.ts | 9 +++++++-- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/common/constants/parameter-constants.ts b/src/common/constants/parameter-constants.ts index a80ea0e..d982939 100644 --- a/src/common/constants/parameter-constants.ts +++ b/src/common/constants/parameter-constants.ts @@ -6,7 +6,8 @@ const uniformResponseParamName = 'uniformresponse'; const recordCountHeaderName = 'total-record-count'; const sinceParamName = 'since'; -const idRegex = /[0-9\-A-Za-z]+/; +const idMaxLength = 100; +const idRegex = /^[0-9\-A-Za-z]{1,100}$/; const idName = 'rowId'; const casesAttachmentsFieldName = 'No Intervention'; @@ -22,6 +23,7 @@ export { uniformResponseParamName, recordCountHeaderName, sinceParamName, + idMaxLength, idRegex, idName, casesAttachmentsFieldName, diff --git a/src/common/constants/upstream-constants.ts b/src/common/constants/upstream-constants.ts index 7ccc0ed..555849f 100644 --- a/src/common/constants/upstream-constants.ts +++ b/src/common/constants/upstream-constants.ts @@ -16,6 +16,8 @@ const pageSizeMax = 100; const pageSizeDefault = 10; const startRowNumMin = 0; const startRowNumDefault = 0; +const visitDetailsMax = 100; +const visitDescriptionMax = 4000; export { baseUrlEnvVarName, @@ -36,4 +38,6 @@ export { pageSizeDefault, startRowNumMin, startRowNumDefault, + visitDetailsMax, + visitDescriptionMax, }; diff --git a/src/dto/filter-query-params.dto.ts b/src/dto/filter-query-params.dto.ts index 6b00b6f..aa49f15 100644 --- a/src/dto/filter-query-params.dto.ts +++ b/src/dto/filter-query-params.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { Expose } from 'class-transformer'; +import { Exclude, Expose } from 'class-transformer'; import { IsEnum, IsInt, @@ -21,6 +21,7 @@ import { } from '../common/constants/upstream-constants'; import { sinceParamName } from '../common/constants/parameter-constants'; +@Exclude() export class FilterQueryParams { @IsOptional() @IsISO8601({ strict: true }) diff --git a/src/dto/id-path-params.dto.ts b/src/dto/id-path-params.dto.ts index 0fd4b82..f93c7d6 100644 --- a/src/dto/id-path-params.dto.ts +++ b/src/dto/id-path-params.dto.ts @@ -1,12 +1,18 @@ import { ApiProperty } from '@nestjs/swagger'; import { Matches } from 'class-validator'; -import { idName, idRegex } from '../common/constants/parameter-constants'; +import { + idMaxLength, + idName, + idRegex, +} from '../common/constants/parameter-constants'; export class IdPathParams { @Matches(idRegex) @ApiProperty({ example: 'Entity-Id-Here', description: 'The Entity Id for your selected record type.', + maxLength: idMaxLength, + pattern: idRegex.toString().replaceAll('/', ''), }) [idName]: string; } diff --git a/src/dto/post-in-person-visit.dto.ts b/src/dto/post-in-person-visit.dto.ts index 10799ce..1712ee4 100644 --- a/src/dto/post-in-person-visit.dto.ts +++ b/src/dto/post-in-person-visit.dto.ts @@ -1,12 +1,14 @@ import { Expose, Transform } from 'class-transformer'; import { isPastISO8601Date } from '../helpers/utilities/utilities.service'; import { ApiProperty, ApiSchema } from '@nestjs/swagger'; -import { IsEnum, IsNotEmpty } from 'class-validator'; +import { IsEnum, IsNotEmpty, MaxLength } from 'class-validator'; import { VisitDetails } from '../common/constants/enumerations'; import { childVisitEntityIdFieldName, childVisitIdirFieldName, childVisitType, + visitDescriptionMax, + visitDetailsMax, } from '../common/constants/upstream-constants'; @ApiSchema({ name: 'PostInPersonVisitRequest' }) @@ -24,21 +26,24 @@ export class PostInPersonVisitDto { }) 'Date of visit': string; - // TODO: limit string length once given info about limits @IsNotEmpty() + @MaxLength(visitDescriptionMax) @Expose() @ApiProperty({ example: 'Comments here', description: 'Visit comments', + maxLength: visitDescriptionMax, }) 'Visit Description': string; @IsEnum(VisitDetails) + @MaxLength(visitDetailsMax) @Expose() @ApiProperty({ example: VisitDetails.PrivateVisitInHome, description: 'The visit type', enum: VisitDetails, + maxLength: visitDetailsMax, }) 'Visit Details Value': string; } From 1bea05e3d797b4ba3a860d03ea697c9a40e392b6 Mon Sep 17 00:00:00 2001 From: hannah-macdonald1 Date: Thu, 21 Nov 2024 11:56:28 -0700 Subject: [PATCH 2/2] add exclude --- src/dto/post-in-person-visit.dto.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dto/post-in-person-visit.dto.ts b/src/dto/post-in-person-visit.dto.ts index 1712ee4..41ffe90 100644 --- a/src/dto/post-in-person-visit.dto.ts +++ b/src/dto/post-in-person-visit.dto.ts @@ -1,4 +1,4 @@ -import { Expose, Transform } from 'class-transformer'; +import { Exclude, Expose, Transform } from 'class-transformer'; import { isPastISO8601Date } from '../helpers/utilities/utilities.service'; import { ApiProperty, ApiSchema } from '@nestjs/swagger'; import { IsEnum, IsNotEmpty, MaxLength } from 'class-validator'; @@ -11,6 +11,7 @@ import { visitDetailsMax, } from '../common/constants/upstream-constants'; +@Exclude() @ApiSchema({ name: 'PostInPersonVisitRequest' }) export class PostInPersonVisitDto { @Transform(({ value }) => {