refactor: code review 기반 품질 개선
- HonoVariables 타입 중앙화 (types.ts로 추출, 5개 파일 중복 제거) - 6시간 pricing update cron 핸들러 추가 (syncPricingOnly 메서드) - Response.json() → c.json() 패턴 통일 (Hono 표준) - SORT_FIELD_MAP 중앙화 (constants.ts, 12개 필드 지원) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -129,22 +129,32 @@ export const TABLES = {
|
||||
// ============================================================
|
||||
|
||||
/**
|
||||
* Valid sort fields for instance queries
|
||||
* Mapping of user-facing sort field names to database column names
|
||||
*
|
||||
* This is the single source of truth for sort field validation and mapping.
|
||||
* Query aliases: it=instance_types, pr=pricing, p=providers, r=regions
|
||||
*/
|
||||
export const VALID_SORT_FIELDS = [
|
||||
'price',
|
||||
'hourly_price',
|
||||
'monthly_price',
|
||||
'vcpu',
|
||||
'memory_mb',
|
||||
'memory_gb',
|
||||
'storage_gb',
|
||||
'instance_name',
|
||||
'provider',
|
||||
'region',
|
||||
] as const;
|
||||
export const SORT_FIELD_MAP: Record<string, string> = {
|
||||
price: 'pr.hourly_price',
|
||||
hourly_price: 'pr.hourly_price',
|
||||
monthly_price: 'pr.monthly_price',
|
||||
vcpu: 'it.vcpu',
|
||||
memory: 'it.memory_mb',
|
||||
memory_mb: 'it.memory_mb',
|
||||
memory_gb: 'it.memory_mb', // Note: memory_gb is converted to memory_mb at query level
|
||||
storage_gb: 'it.storage_gb',
|
||||
name: 'it.instance_name',
|
||||
instance_name: 'it.instance_name',
|
||||
provider: 'p.name',
|
||||
region: 'r.region_code',
|
||||
} as const;
|
||||
|
||||
export type ValidSortField = typeof VALID_SORT_FIELDS[number];
|
||||
/**
|
||||
* Valid sort fields for instance queries (derived from SORT_FIELD_MAP)
|
||||
*/
|
||||
export const VALID_SORT_FIELDS = Object.keys(SORT_FIELD_MAP) as ReadonlyArray<string>;
|
||||
|
||||
export type ValidSortField = keyof typeof SORT_FIELD_MAP;
|
||||
|
||||
/**
|
||||
* Valid sort orders
|
||||
|
||||
Reference in New Issue
Block a user