Implement case transformer server - #1184
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am approving your solution. The server correctly parses query parameters, validates text and toCase, aggregates multiple errors, invokes convertToCase, and returns the expected JSON structure and error messages. One minor improvement: on line 28 you validate with toCase.toUpperCase(), but on line 46 you pass the original toCase to convertToCase. If convertToCase expects uppercase values (matching supportedCases), this could lead to inconsistent behavior. Consider passing toCase.toUpperCase() to convertToCase or normalizing input inside convertToCase for consistency. Overall, functionality appears intact and requirements are met—nice work.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
|
|
||
| if (toCase !== null && !supportedCases.includes(toCase.toUpperCase())) { | ||
| errors.push({ | ||
| message: | ||
| 'This case is not supported. Available cases: SNAKE, KEBAB, ' + | ||
| 'CAMEL, PASCAL, UPPER.', | ||
| }); | ||
| } | ||
|
|
||
| if (errors.length > 0) { | ||
| res.setHeader('Content-Type', 'application/json'); | ||
| res.statusCode = 400; | ||
| res.statusMessage = 'Bad request'; | ||
| res.end(JSON.stringify({ errors })); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| const result = convertToCase(text, toCase); |
There was a problem hiding this comment.
The validation converts toCase to uppercase for checking (toCase.toUpperCase()), but line 46 passes the original toCase value to convertToCase. If the business logic expects uppercase values (as the supportedCases array suggests), this inconsistency could cause issues. Consider passing toCase.toUpperCase() to convertToCase for consistency.
No description provided.