AI Skill Report Card
Creating TypeScript Controllers
Quick Start14 / 15
TypeScriptexport const createEntityController = async ( body: Namespace.Entity.CreateEntityParams, ): Promise<AxiosResponse<Namespace.Entity.Entity, any>> => { const url = '/api/entity/'; 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 more examples covering different CRUD operations (GET, PUT, DELETE) not just POST/creation
Workflow13 / 15
-
Identify Parameters
- Determine if URL parameters are needed (e.g.,
versao,id) - Identify the body/payload type required
- Determine if URL parameters are needed (e.g.,
-
Define Function Signature
- URL parameters first (if any)
- Body parameter last
- Return type:
Promise<AxiosResponse<EntityType, any>>
-
Build URL Path
- Use template literals for dynamic parameters
- Follow REST conventions:
/api/module/entity/or/api/module/param/entity/
-
Implement Request
- Use
genRequestInstance()for authentication - Use
instance.post()for creation - Standard error handling pattern
- Use
-
Add JSDoc
- Document all parameters
- Document return type
- Document potential errors
Recommendation▾
Include template/framework for complete controller file structure with imports and type definitions
Examples18 / 20
Example 1: Simple creation (no URL parameters) Input: Create a "user" controller Output:
TypeScript/** * Creates a new user * @param body - User creation parameters * @returns Promise with created user data * @throws Error when request fails */ export const createUserController = async ( body: User.CreateUserParams, ): Promise<AxiosResponse<User.User, any>> => { const url = '/api/user/'; 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); } };
Example 2: Creation with URL parameter Input: Create a "task" controller within a "project" Output:
TypeScript/** * Creates a new task within a project * @param projectId - ID of the project * @param body - Task creation parameters * @returns Promise with created task data * @throws Error when request fails */ export const createTaskController = async ( projectId: Project.Project['id'], body: Task.CreateTaskParams, ): Promise<AxiosResponse<Task.Task, any>> => { const url = `/api/project/${projectId}/task/`; 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▾
Expand completeness by covering authentication patterns, response handling, and integration with the broader API architecture
Best Practices
- Naming Convention:
create{EntityName}Controller - File Naming:
controller.tsor{entity-name}.controller.ts - URL Structure: Follow existing API patterns in codebase
- Parameter Order: URL parameters first, body parameter last
- Error Handling: Use standard pattern - axios instance handles auth errors
- Type Safety: Reference types from
typings.d.ts - JSDoc: Always document parameters, returns, and throws
Common Pitfalls
- Don't add custom error handling -
genRequestInstance()handles auth/token refresh - Don't assume type names - always verify against
typings.d.ts - Don't hardcode namespaces - follow the existing pattern in the codebase
- Don't use query parameters for POST requests - only URL path parameters
- Don't forget the trailing slash in URLs (
/api/entity/not/api/entity)