AI Skill Report Card
Creating PATCH Controllers
Quick Start15 / 15
TypeScriptexport const updateUserController = async ( id: User['id'], params: UpdateUserParams, ): Promise<AxiosResponse<User, any>> => { const url = `/api/users/${id}/`; const instance = genRequestInstance(); try { const response = await instance.patch(url, params); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Recommendation▾
Remove the Portuguese error messages ('Erro na requisição:') and make examples language-neutral
Workflow12 / 15
- Function signature:
export const update{Entity}Controller = async ( - Parameters: Add URL parameters first (0-M), then body params
- Return type:
Promise<AxiosResponse<ReturnType, any>> - URL construction:
/api/{module}/{urlParams}/{entity-id}/ - Request execution: Use
instance.patch(url, params) - Error handling: Standard try/catch with console.error
Progress checklist:
- Define entity and operation name
- Identify URL parameters (path segments)
- Define body parameter type
- Define response entity type
- Construct URL pattern
- Implement standard error handling
Recommendation▾
Add information about the genRequestInstance() function or how to configure the Axios instance
Examples20 / 20
Example 1 - Single ID parameter: Input: Entity "Product", single ID, body type "UpdateProductParams", return "Product" Output:
TypeScriptexport const updateProductController = async ( id: Product['id'], params: UpdateProductParams, ): Promise<AxiosResponse<Product, any>> => { const url = `/api/products/${id}/`; const instance = genRequestInstance(); try { const response = await instance.patch(url, params); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Example 2 - Multiple URL parameters: Input: Entity "Task", URL params "projectId" and "taskId", body "UpdateTaskParams", return "Task" Output:
TypeScriptexport const updateTaskController = async ( projectId: Project['id'], taskId: Task['id'], params: UpdateTaskParams, ): Promise<AxiosResponse<Task, any>> => { const url = `/api/projects/${projectId}/tasks/${taskId}/`; const instance = genRequestInstance(); try { const response = await instance.patch(url, params); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Example 3 - No URL parameters: Input: Entity "Settings", no URL params, body "UpdateSettingsParams", return "Settings" Output:
TypeScriptexport const updateSettingsController = async ( params: UpdateSettingsParams, ): Promise<AxiosResponse<Settings, any>> => { const url = `/api/settings/`; const instance = genRequestInstance(); try { const response = await instance.patch(url, params); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Recommendation▾
Include examples of the UpdateParams interfaces and explain partial update patterns vs full replacement
Best Practices
- Function naming: Always use
update{Entity}Controllerpattern - Parameter order: URL parameters first (in path order), body params last
- Type safety: Use entity type references (
Entity['id']) for IDs - URL format: Follow REST convention
/api/{resource}/{id}/with trailing slash - Error logging: Always log errors with 'Erro na requisição:' prefix
- Consistent spacing: Two blank lines between controller functions
Common Pitfalls
- Don't mix parameter order - URL params always come before body
- Don't forget trailing slash in URLs
- Don't use generic error messages - keep "Erro na requisição:" standard
- Don't handle errors beyond logging and rejecting - let Axios handle status codes
- Don't use
anyfor body or response types - always define specific interfaces