AI Skill Report Card
Creating TypeScript Update Controllers
Quick Start15 / 15
TypeScriptexport const updateEntityController = async ( id: Entity.Entity['id'], params: Entity.UpdateEntityParams, ): Promise<AxiosResponse<Entity.Entity, any>> => { const url = `/api/entity/${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▾
Add a template section with placeholders for entity name, parameters, and types to make generation more systematic
Workflow12 / 15
-
Identify entity and parameters
- Entity name (for function naming)
- Entity ID type
- Additional URL parameters (if any)
- Update payload type
-
Generate function signature
- Function name:
update{EntityName}Controller - Parameters: additional params first, then entity ID, then update payload
- Return type:
AxiosResponse<EntityType, any>
- Function name:
-
Build URL pattern
- Base:
/api/module/entity/${id}/ - With parameters:
/api/module/versao/${versao}/entity/${id}/
- Base:
-
Add JSDoc documentation
@paramfor each parameter@returnsfor response type@throwsfor error cases
Recommendation▾
Include validation patterns and error handling strategies beyond basic try-catch
Examples20 / 20
Example 1 (Simple entity): Input: Entity "User", no additional parameters
TypeScript/** * Updates a user entity * @param id - User ID * @param params - Update parameters * @returns Promise with user data response * @throws Error if request fails */ export const updateUserController = async ( id: User.User['id'], params: User.UpdateUserParams, ): Promise<AxiosResponse<User.User, any>> => { const url = `/api/user/${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 (With additional parameters): Input: Entity "Funcionario" with "empresaId" parameter
TypeScript/** * Updates a funcionario entity within a specific empresa * @param empresaId - Empresa ID * @param id - Funcionario ID * @param params - Update parameters * @returns Promise with funcionario data response * @throws Error if request fails */ export const updateFuncionarioController = async ( empresaId: Empresa.Empresa['id'], id: Funcionario.Funcionario['id'], params: Funcionario.UpdateFuncionarioParams, ): Promise<AxiosResponse<Funcionario.Funcionario, any>> => { const url = `/api/empresa/${empresaId}/funcionario/${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▾
Provide guidance on testing these controllers, including mock examples and common test scenarios
Best Practices
- Function naming: Always use
update{EntityName}Controllerformat - Parameter order: Additional URL params first, entity ID second, update payload last
- URL structure: Follow REST conventions with clear hierarchy
- Type safety: Use proper TypeScript namespacing for entity types
- Error handling: Use consistent error logging and rejection
- JSDoc: Include comprehensive documentation for all parameters
Common Pitfalls
- Wrong parameter order: Entity ID should come after additional URL parameters
- Missing JSDoc: Always document parameters and return types
- Incorrect URL structure: Ensure URL matches the API endpoint pattern
- Type mismatches: Verify that entity types exist in typings.d.ts before using
- Missing async/await: Controller functions must be async