AI Skill Report Card

Creating TypeScript Controllers

B75·May 6, 2026·Source: Web
14 / 15
TypeScript
export 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
13 / 15
  1. Identify Parameters

    • Determine if URL parameters are needed (e.g., versao, id)
    • Identify the body/payload type required
  2. Define Function Signature

    • URL parameters first (if any)
    • Body parameter last
    • Return type: Promise<AxiosResponse<EntityType, any>>
  3. Build URL Path

    • Use template literals for dynamic parameters
    • Follow REST conventions: /api/module/entity/ or /api/module/param/entity/
  4. Implement Request

    • Use genRequestInstance() for authentication
    • Use instance.post() for creation
    • Standard error handling pattern
  5. 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
18 / 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
  • Naming Convention: create{EntityName}Controller
  • File Naming: controller.ts or {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
  • 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)
0
Grade BAI Skill Framework
Scorecard
Criteria Breakdown
Quick Start
14/15
Workflow
13/15
Examples
18/20
Completeness
14/20
Format
13/15
Conciseness
13/15