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.
This commit is contained in:
2025-12-08 02:57:49 -05:00
parent 700832550c
commit ca5a13ea51

View File

@@ -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(),
});