AI Skill Report Card

Creating TypeScript CRUD Controllers

B+78·May 6, 2026·Source: Web
14 / 15
TypeScript
import { 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.
12 / 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:

  1. Import Dependencies

    TypeScript
    import { genRequestInstance } from '@/request'; import { AxiosResponse } from 'axios';
  2. Define Function Signature

    • Use camelCase: deleteEntityNameController
    • Parameter order: URL params first, then entity ID
    • Return type: Promise<AxiosResponse<null, any>>
  3. Build URL Pattern

    • With parameters: /api/module/versao/${param}/entity/${id}/
    • Without parameters: /api/module/entity/${id}/
  4. Add JSDoc

    TypeScript
    /** * Operation description * @param param1 - Description * @param id - The entity ID * @returns Promise with axios response * @throws Error when request fails */
  5. 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.
18 / 20

Example 1: Delete with URL Parameter Input: Entity "AdicionalNoturno" with versao parameter Output:

TypeScript
export 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:

TypeScript
export 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

TypeScript
export 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).
  • 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
  • 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
0
Grade B+AI Skill Framework
Scorecard
Criteria Breakdown
Quick Start
14/15
Workflow
12/15
Examples
18/20
Completeness
16/20
Format
15/15
Conciseness
13/15