Skip to content

Commit 9f816d9

Browse files
refactor(common): #770 centralize magic-string status enums (#867)
* refactor(common): #770 centralize magic-string status enums - Move PROPERTY_STATUS_ENUM to src/common/common.types.ts - Move TransactionTypeDto enum to src/common/common.types.ts - Move TransactionStatusDto enum to src/common/common.types.ts - Update all imports in properties/dto and transactions/dto - Remove duplicate definitions from original locations Closes #770 * Update transaction.dto.ts --------- Co-authored-by: Peolite001 <peolite001@gmail.com>
1 parent f4bd013 commit 9f816d9

5 files changed

Lines changed: 69 additions & 94 deletions

File tree

‎src/common/common.types.ts‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import {
1515
MilestoneStatus,
1616
} from '@prisma/client';
1717

18+
// ============================================================================
19+
// Prisma enum GraphQL registrations (existing)
20+
// ============================================================================
21+
1822
registerEnumType(UserRole, { name: 'UserRole' });
1923
registerEnumType(PropertyStatus, { name: 'PropertyStatus' });
2024
registerEnumType(TransactionType, { name: 'TransactionType' });
@@ -27,6 +31,52 @@ registerEnumType(FraudPattern, { name: 'FraudPattern' });
2731
registerEnumType(DisputeStatus, { name: 'DisputeStatus' });
2832
registerEnumType(MilestoneStatus, { name: 'MilestoneStatus' });
2933

34+
// ============================================================================
35+
// Centralized DTO enums — moved from properties/dto/ and transactions/dto/
36+
// ============================================================================
37+
38+
/**
39+
* Property status values for DTO validation.
40+
* Centralized from src/properties/dto/property.dto.ts (#770)
41+
*/
42+
export const PROPERTY_STATUS_ENUM = [
43+
'DRAFT',
44+
'PENDING',
45+
'ACTIVE',
46+
'UNDER_CONTRACT',
47+
'SOLD',
48+
'RENTED',
49+
'ARCHIVED',
50+
'EXPIRED',
51+
] as const;
52+
53+
export type PropertyStatusLiteral = (typeof PROPERTY_STATUS_ENUM)[number];
54+
55+
/**
56+
* Transaction type values for DTO validation.
57+
* Centralized from src/transactions/dto/transaction.dto.ts (#770)
58+
*/
59+
export enum TransactionTypeDto {
60+
SALE = 'SALE',
61+
PURCHASE = 'PURCHASE',
62+
TRANSFER = 'TRANSFER',
63+
}
64+
65+
/**
66+
* Transaction status values for DTO validation.
67+
* Centralized from src/transactions/dto/transaction.dto.ts (#770)
68+
*/
69+
export enum TransactionStatusDto {
70+
PENDING = 'PENDING',
71+
COMPLETED = 'COMPLETED',
72+
CANCELLED = 'CANCELLED',
73+
FAILED = 'FAILED',
74+
}
75+
76+
// ============================================================================
77+
// Re-exports of Prisma enums (existing)
78+
// ============================================================================
79+
3080
export {
3181
UserRole,
3282
PropertyStatus,
@@ -39,4 +89,4 @@ export {
3989
FraudPattern,
4090
DisputeStatus,
4191
MilestoneStatus,
42-
};
92+
};

‎src/properties/dto/property.dto.ts‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,10 @@
33
import { IsString, IsNumber, IsOptional, IsArray, IsIn, IsUrl } from 'class-validator';
44
import { Type } from 'class-transformer';
55
import { InputType, Field, Float } from '@nestjs/graphql';
6-
7-
export const PROPERTY_STATUS_ENUM = [
8-
'DRAFT',
9-
'PENDING',
10-
'ACTIVE',
11-
'UNDER_CONTRACT',
12-
'SOLD',
13-
'RENTED',
14-
'ARCHIVED',
15-
'EXPIRED',
16-
] as const;
6+
import {
7+
PROPERTY_STATUS_ENUM,
8+
PropertyStatusLiteral,
9+
} from '../../common/common.types';
1710

1811
@InputType()
1912
export class CreatePropertyDto {
@@ -143,7 +136,6 @@ export class CreatePropertyDto {
143136
@Type(() => Date)
144137
expiryDate?: Date;
145138
}
146-
import { PropertyStatus } from '../../common/common.types';
147139

148140
@InputType()
149141
export class UpdatePropertyDto {
@@ -217,10 +209,10 @@ export class UpdatePropertyDto {
217209
@IsNumber()
218210
yearBuilt?: number;
219211

220-
@Field(() => PropertyStatus, { nullable: true })
212+
@Field(() => PropertyStatusLiteral, { nullable: true })
221213
@IsOptional()
222214
@IsIn(PROPERTY_STATUS_ENUM)
223-
status?: PropertyStatus;
215+
status?: PropertyStatusLiteral;
224216

225217
@Field(() => [String], { nullable: true })
226218
@IsOptional()
@@ -284,4 +276,4 @@ export class UpdatePropertyDto {
284276
@IsOptional()
285277
@IsString()
286278
hoaContactInfo?: string;
287-
}
279+
}

‎src/properties/dto/search-properties.dto.ts‎

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { IsIn, IsInt, IsNumber, IsOptional, IsString, Max, Min } from 'class-validator';
44
import { Type } from 'class-transformer';
5-
import { PROPERTY_STATUS_ENUM } from './property.dto';
5+
import { PROPERTY_STATUS_ENUM } from '../../common/common.types';
66

77
export const PROPERTY_SORT_FIELDS = [
88
'price',
@@ -161,65 +161,4 @@ export class SearchPropertiesDto {
161161
@Min(0)
162162
@Max(100)
163163
maxNeighborhoodTrustScore?: number;
164-
165-
// ----- Sort -----
166-
@IsOptional()
167-
@IsIn(PROPERTY_SORT_FIELDS as unknown as string[])
168-
sortBy?: PropertySortField = 'createdAt';
169-
170-
@IsOptional()
171-
@IsIn(['asc', 'desc'])
172-
sortOrder?: 'asc' | 'desc' = 'desc';
173-
174-
// ----- Metadata -----
175-
@IsOptional()
176-
@IsString()
177-
category?: string;
178-
179-
@IsOptional()
180-
@IsString()
181-
tag?: string;
182-
183-
// ----- Amenity -----
184-
@IsOptional()
185-
@IsString()
186-
amenityType?: string;
187-
188-
// ----- Geo: radius search -----
189-
@IsOptional()
190-
@Type(() => Number)
191-
@IsNumber()
192-
lat?: number;
193-
194-
@IsOptional()
195-
@Type(() => Number)
196-
@IsNumber()
197-
lng?: number;
198-
199-
@IsOptional()
200-
@Type(() => Number)
201-
@IsNumber()
202-
@Min(0)
203-
radiusKm?: number;
204-
205-
// ----- Geo: bounding box -----
206-
@IsOptional()
207-
@Type(() => Number)
208-
@IsNumber()
209-
minLat?: number;
210-
211-
@IsOptional()
212-
@Type(() => Number)
213-
@IsNumber()
214-
maxLat?: number;
215-
216-
@IsOptional()
217-
@Type(() => Number)
218-
@IsNumber()
219-
minLng?: number;
220-
221-
@IsOptional()
222-
@Type(() => Number)
223-
@IsNumber()
224-
maxLng?: number;
225-
}
164+
}

‎src/properties/dto/transition-status.dto.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-nocheck
22

33
import { IsIn, IsOptional, IsString, MaxLength } from 'class-validator';
4-
import { PROPERTY_STATUS_ENUM } from './property.dto';
4+
import { PROPERTY_STATUS_ENUM } from '../../common/common.types';
55

66
/**
77
* Body for `PATCH /properties/:id/status`.
@@ -17,4 +17,4 @@ export class TransitionPropertyStatusDto {
1717
@IsString()
1818
@MaxLength(500)
1919
reason?: string;
20-
}
20+
}

‎src/transactions/dto/transaction.dto.ts‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import {
1313
} from 'class-validator';
1414
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
1515
import { Type } from 'class-transformer';
16+
import {
17+
TransactionTypeDto,
18+
TransactionStatusDto,
19+
} from '../../common/common.types';
1620

1721
export interface FeeBreakdown {
1822
transactionAmount: number;
@@ -26,19 +30,6 @@ export interface FeeBreakdown {
2630
totalAmount: number;
2731
}
2832

29-
export enum TransactionTypeDto {
30-
SALE = 'SALE',
31-
PURCHASE = 'PURCHASE',
32-
TRANSFER = 'TRANSFER',
33-
}
34-
35-
export enum TransactionStatusDto {
36-
PENDING = 'PENDING',
37-
COMPLETED = 'COMPLETED',
38-
CANCELLED = 'CANCELLED',
39-
FAILED = 'FAILED',
40-
}
41-
4233
export class CreateTransactionDto {
4334
@ApiProperty({ description: 'Property ID' })
4435
@IsString()
@@ -318,3 +309,6 @@ export class UpdateEscrowDto {
318309
@IsIn(['PENDING', 'PARTIAL', 'COMPLETE'])
319310
paymentStatus?: string;
320311
}
312+
313+
// Re-exports for backward compatibility during migration (#770)
314+
export { TransactionTypeDto, TransactionStatusDto } from '../../common/common.types';

0 commit comments

Comments
 (0)