AI Skill Report Card
Creating TypeScript CRUD Controllers
Quick Start14 / 15
TypeScriptimport { genRequestInstance } from '@/request'; import { AxiosResponse } from 'axios'; /** * Deletes an entity by ID * @param id - The entity ID to delete * @returns Promise with axios response * @throws Error when request fails */ export const deleteEntityController = async ( id: Entity['id'], ): Promise<AxiosResponse<null, any>> => { const url = `/api/entity/${id}/`; const instance = genRequestInstance(); try { const response = await instance.delete(url); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Recommendation▾
Condense the workflow checklist - it's too granular for the task complexity. Focus on high-level decision points.
Workflow12 / 15
Progress:
- Identify entity name and endpoint structure
- Determine if controller needs URL parameters
- Create controller function with proper typing
- Add JSDoc documentation
- Implement axios instance and request
- Add error handling pattern
Step-by-step Process:
-
Import Dependencies
TypeScriptimport { genRequestInstance } from '@/request'; import { AxiosResponse } from 'axios'; -
Define Function Signature
- Use camelCase:
deleteEntityNameController - Parameter order: URL params first, then entity ID
- Return type:
Promise<AxiosResponse<null, any>>
- Use camelCase:
-
Build URL Pattern
- With parameters:
/api/module/versao/${param}/entity/${id}/ - Without parameters:
/api/module/entity/${id}/
- With parameters:
-
Add JSDoc
TypeScript/** * Operation description * @param param1 - Description * @param id - The entity ID * @returns Promise with axios response * @throws Error when request fails */ -
Implement Request Logic
- Create axios instance
- Make request with try/catch
- Return response or reject error
Recommendation▾
The Quick Start example could show a more complete scenario with both URL parameter and simple cases upfront.
Examples18 / 20
Example 1: Delete with URL Parameter Input: Entity "AdicionalNoturno" with versao parameter Output:
TypeScriptexport const deleteAdicionalNoturnoController = async ( versao: Planejamento.Versao.Versao['id'], id: Pessoal.Premissas.AdicionalNoturno.AdicionalNoturno['id'], ): Promise<AxiosResponse<null, any>> => { const url = `/api/pessoal/versao/${versao}/adicional-noturno/${id}/`; const instance = genRequestInstance(); try { const response = await instance.delete(url); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Example 2: Simple Delete Input: Entity "Area" without parameters Output:
TypeScriptexport const deleteAreaController = async ( id: Planejamento.Cadastro.Area.Area['id'], ): Promise<AxiosResponse<null, any>> => { const url = `/api/planejamento/area/${id}/`; const instance = genRequestInstance(); try { const response = await instance.delete(url); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Example 3: Create/Update with Body
TypeScriptexport const createEntityController = async ( data: Entity.Create, ): Promise<AxiosResponse<Entity.Entity, any>> => { const url = `/api/module/entity/`; const instance = genRequestInstance(); try { const response = await instance.post(url, data); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Recommendation▾
Add a template section with fill-in-the-blank boilerplate that covers the most common patterns (GET, POST, PUT, DELETE).
Best Practices
- Naming Convention:
{verb}{EntityName}Controller(deleteAreaController, createUserController) - URL Structure: Follow REST patterns with trailing slashes
- Parameter Order: URL parameters before entity ID
- Error Handling: Use consistent try/catch with console.error
- Type Safety: Use proper TypeScript types from entity definitions
- JSDoc: Always include parameter descriptions and return types
Common Pitfalls
- Don't handle HTTP status codes manually - axios instance handles it
- Don't modify the error handling pattern - keep it consistent
- Don't forget trailing slash in URLs
- Don't use query parameters for entity IDs - they go in URL path
- Don't omit JSDoc documentation
- Don't use async/await without try/catch blocks