From ca5a13ea513d9da542797f2d48d94b31c73f189a Mon Sep 17 00:00:00 2001 From: Alexander Zinn Date: Mon, 8 Dec 2025 02:57:49 -0500 Subject: [PATCH] Refactor asset type handling in AssetController schema - Replaced native enum for asset types with a constant array using z.enum for improved type safety and maintainability in create and update asset schemas. --- backend-api/src/controllers/AssetController.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend-api/src/controllers/AssetController.ts b/backend-api/src/controllers/AssetController.ts index 3cd5a98..517ab91 100644 --- a/backend-api/src/controllers/AssetController.ts +++ b/backend-api/src/controllers/AssetController.ts @@ -3,17 +3,18 @@ import {z} from 'zod'; import {AssetService} from '../services/AssetService'; import {AssetRepository} from '../repositories/AssetRepository'; import {getUserId} from '../middleware/auth'; -type AssetType = 'cash' | 'investment' | 'property' | 'vehicle' | 'other'; + +const ASSET_TYPES = ['cash', 'investment', 'property', 'vehicle', 'other'] as const; const createAssetSchema = z.object({ name: z.string().min(1), - type: z.nativeEnum(AssetType), + type: z.enum(ASSET_TYPES), value: z.number().min(0), }); const updateAssetSchema = z.object({ name: z.string().min(1).optional(), - type: z.nativeEnum(AssetType).optional(), + type: z.enum(ASSET_TYPES).optional(), value: z.number().min(0).optional(), });