AI Skill Report Card
Creating TypeScript Controller
Quick Start13 / 15
TypeScriptexport const create{EntityName}Controller = async ( body: {Namespace}.{EntityName}.Create{EntityName}Params, ): Promise<AxiosResponse<{Namespace}.{EntityName}.{EntityName}, any>> => { const url = '/api/{endpoint}/'; const instance = genRequestInstance(); try { const response = await instance.post(url, body); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Recommendation▾
Add template sections for different controller patterns (with/without path params, different namespaces) to provide clear frameworks
Workflow12 / 15
Progress:
- Identify entity name and required parameters
- Check for existing typings in typings.d.ts
- Determine URL structure and path parameters
- Generate JSDoc documentation
- Create controller function with proper typing
- Add error handling pattern
Step-by-step Process
-
Extract entity information
- Entity name (PascalCase)
- Namespace hierarchy
- Required path parameters
-
Verify typings exist
Create{EntityName}Paramsinterface{EntityName}response interface- Ask user if missing
-
Build URL pattern
- Base:
/api/{module}/{endpoint}/ - With params:
/api/{module}/versao/${versao}/{endpoint}/
- Base:
-
Generate function
- Function name:
create{EntityName}Controller - Parameters: path params + body
- Return type:
Promise<AxiosResponse<EntityType, any>>
- Function name:
Recommendation▾
Include edge cases like handling multiple path parameters, optional parameters, or different HTTP status codes
Examples18 / 20
Example 1: Controller with path parameter Input: "Create controller for AdicionalNoturno with versao parameter" Output:
TypeScript/** * Creates a new AdicionalNoturno * @param versao - Version ID for the planning * @param params - AdicionalNoturno creation parameters * @returns Promise with AdicionalNoturno response * @throws Error when request fails */ export const createAdicionalNoturnoController = async ( versao: Planejamento.Versao.Versao['id'], params: Pessoal.Premissas.AdicionalNoturno.CreateAdicionalNoturnoParams, ): Promise< AxiosResponse<Pessoal.Premissas.AdicionalNoturno.AdicionalNoturno, any> > => { const url = `/api/pessoal/versao/${versao}/adicional-noturno/`; const instance = genRequestInstance(); try { const response = await instance.post(url, params); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Example 2: Simple controller without parameters Input: "Create controller for Area entity" Output:
TypeScript/** * Creates a new Area * @param body - Area creation parameters * @returns Promise with Area response * @throws Error when request fails */ export const createAreaController = async ( body: Planejamento.Cadastro.Area.CreateAreaParams, ): Promise<AxiosResponse<Planejamento.Cadastro.Area.Area, any>> => { const url = '/api/planejamento/area/'; const instance = genRequestInstance(); try { const response = await instance.post(url, body); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Recommendation▾
Provide default URL patterns and namespace structures to avoid requiring user input for common cases
Best Practices
- Always use
genRequestInstance()for authenticated requests - Include JSDoc with
@param,@returns, and@throws - Follow naming convention:
create{EntityName}Controller - Path parameters come before body parameter
- Use kebab-case for URL endpoints
- Maintain consistent error handling pattern
Common Pitfalls
- Don't assume typings exist - always verify or ask
- Don't change the established error handling pattern
- Don't mix camelCase with kebab-case in URLs
- Don't omit JSDoc documentation
- Don't modify the axios instance configuration