AI Skill Report Card
Generating TypeScript PATCH 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 templates or code generation patterns that can be filled in programmatically rather than just examples
Workflow10 / 15
Progress:
- Identify entity name and namespace
- Determine URL parameters (beyond entity ID)
- Generate function signature with proper TypeScript types
- Create JSDoc documentation
- Build URL pattern based on parameters
- Implement PATCH request with error handling
Recommendation▾
Include validation patterns and common parameter types (UpdateParams interface structure)
Examples15 / 20
Example 1: Entity with additional URL parameter Input: Create update controller for "AdicionalNoturno" entity with "versao" parameter
Output:
TypeScript/** * Updates an AdicionalNoturno entity * @param versao - The version ID for the planning * @param id - The AdicionalNoturno entity ID to update * @param params - The update parameters * @returns Promise resolving to the updated AdicionalNoturno entity * @throws Error when request fails or validation errors occur */ export const updateAdicionalNoturnoController = async ( versao: Planejamento.Versao.Versao['id'], id: Pessoal.Premissas.AdicionalNoturno.AdicionalNoturno['id'], params: Pessoal.Premissas.AdicionalNoturno.UpdateAdicionalNoturnoParams, ): Promise< AxiosResponse<Pessoal.Premissas.AdicionalNoturno.AdicionalNoturno, any> > => { const url = `/api/pessoal/versao/${versao}/adicional-noturno/${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: Simple entity without additional parameters Input: Create update controller for "Area" entity
Output:
TypeScript/** * Updates an Area entity * @param id - The Area entity ID to update * @param params - The update parameters * @returns Promise resolving to the updated Area entity * @throws Error when request fails or validation errors occur */ export const updateAreaController = async ( id: Planejamento.Cadastro.Area.Area['id'], params: Planejamento.Cadastro.Area.UpdateAreaParams, ): Promise<AxiosResponse<Planejamento.Cadastro.Area.Area, any>> => { const url = `/api/planejamento/area/${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 decision tree for determining URL patterns based on entity relationships and hierarchy
Best Practices
- Use camelCase for controller function names ending with "Controller"
- Always include proper TypeScript generics for AxiosResponse
- Follow URL pattern:
/api/module/[parent-param/]entity-name/${id}/ - Use kebab-case for URL segments
- Include comprehensive JSDoc with @param, @returns, and @throws
- Place additional URL parameters before the entity ID parameter
- Use namespace typing pattern:
Module.Submodule.Entity.Type
Common Pitfalls
- Don't forget the trailing slash in API URLs
- Don't handle errors beyond logging - the axios instance handles authentication
- Don't use query parameters for entity updates - use URL path parameters only
- Don't mix naming conventions - stick to camelCase for functions, kebab-case for URLs
- Don't omit TypeScript types - always specify the complete generic types for AxiosResponse