| 118 | * Validate required fields in request body |
| 119 | */ |
| 120 | export function validateRequiredFields( |
| 121 | body: Record<string, unknown>, |
| 122 | requiredFields: string[] |
| 123 | ): { isValid: true } | { isValid: false; error: string } { |
| 124 | const missingFields = requiredFields.filter((field) => !(field in body)) |
| 125 | |
| 126 | if (missingFields.length > 0) { |
| 127 | return { |
| 128 | isValid: false, |
| 129 | error: `Missing required fields: ${missingFields.join(', ')}`, |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | return { isValid: true } |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Enhanced error categorization for more specific HTTP status codes. |