1- import { ApiHideProperty } from '@nestjs/swagger' ;
1+ import { ApiHideProperty , ApiPropertyOptional } from '@nestjs/swagger' ;
22import { Transform } from 'class-transformer' ;
3- import { PartialType } from '@nestjs/mapped-types' ;
3+ import { IsNumber , IsOptional } from 'class-validator' ;
4+ import { OmitType , PartialType } from '@nestjs/mapped-types' ;
45import { CreateProjectDto } from './create-project.dto' ;
56
7+ /**
8+ * Parses optional project billing-account update input.
9+ *
10+ * @param value Raw `billingAccountId` value from request payload.
11+ * @returns Parsed integer, `null` when clearing, or `undefined` when omitted.
12+ */
13+ function parseOptionalNullableInteger ( value : unknown ) : number | null | undefined {
14+ if ( typeof value === 'undefined' ) {
15+ return undefined ;
16+ }
17+
18+ if ( value === null || value === '' ) {
19+ return null ;
20+ }
21+
22+ const parsed = Number ( value ) ;
23+
24+ if ( Number . isNaN ( parsed ) ) {
25+ return undefined ;
26+ }
27+
28+ return Math . trunc ( parsed ) ;
29+ }
30+
631/**
732 * Resolves whether the patch payload explicitly requests clearing
833 * `billingAccountId`.
@@ -17,9 +42,21 @@ function parseClearBillingAccountFlag(value: unknown): boolean {
1742/**
1843 * Request DTO for `PATCH /projects/:projectId`.
1944 *
20- * Reuses `CreateProjectDto` and makes all fields optional via `PartialType`.
45+ * Reuses `CreateProjectDto`, makes all fields optional via `PartialType`, and
46+ * allows `billingAccountId` to be explicitly cleared with `null` or `''`.
2147 */
22- export class UpdateProjectDto extends PartialType ( CreateProjectDto ) {
48+ export class UpdateProjectDto extends PartialType (
49+ OmitType ( CreateProjectDto , [ 'billingAccountId' ] as const ) ,
50+ ) {
51+ @ApiPropertyOptional ( {
52+ description : 'Project billing account id. Send null or empty string to clear.' ,
53+ nullable : true ,
54+ } )
55+ @IsOptional ( )
56+ @Transform ( ( { value } ) => parseOptionalNullableInteger ( value ) )
57+ @IsNumber ( )
58+ billingAccountId ?: number | null ;
59+
2360 @ApiHideProperty ( )
2461 @Transform ( ( { obj } ) => parseClearBillingAccountFlag ( obj ?. billingAccountId ) )
2562 clearBillingAccountId ?: boolean ;
0 commit comments