AI Skill Report Card
Generated Skill
Quick Start
TypeScriptimport { defaultPaginationValues } from '@/constants/pagination'; import useLoading from '@/hooks/use-loading'; import { updateArrayItem } from '@/utils/update-array-item'; import { message } from 'antd'; import { useState } from 'react'; import { createEntityController, deleteEntityController, getEntitiesController, updateEntityController, } from './entity.controller'; export default () => { const [entities, setEntities] = useState(defaultPaginationValues); const { loading, startLoading, stopLoading } = useLoading(); const getEntities = async (...args: Parameters<typeof getEntitiesController>) => { try { startLoading(); const response = await getEntitiesController(...args); setEntities(response.data); } catch (error) { message.error('Não foi possível obter os dados'); return Promise.reject(); } finally { stopLoading(); } }; return { entities, loading, getEntities }; };
Recommendation▾
Consider adding more specific examples
Workflow
Progress:
- Analyze controller functions to determine available operations
- Set up state with proper typing (paginated or array)
- Implement CRUD operations matching controller signatures
- Add error handling and loading states
- Return hook interface with consistent naming
Recommendation▾
Include edge cases
Model Generation Patterns
Pattern 1: Paginated Data (with querystring)
TypeScriptconst [entities, setEntities] = useState<App.Pagination<EntityType>>(defaultPaginationValues); // GET with pagination const getEntities = async (...args: Parameters<typeof getEntitiesController>) => { const response = await getEntitiesController(...args); setEntities(response.data); }; // CREATE - prepend to results array const createEntity = async (...args: Parameters<typeof createEntityController>) => { const response = await createEntityController(...args); setEntities(prev => ({ ...prev, results: [response.data, ...(prev?.results || [])], count: prev.count + 1, })); };
Pattern 2: Simple Array (no pagination)
TypeScriptconst [entities, setEntities] = useState<EntityType[]>([]); // GET simple array const getEntities = async (...args: Parameters<typeof getEntitiesController>) => { const response = await getEntitiesController(...args); setEntities(response.data); }; // CREATE - prepend to array const createEntity = async (...args: Parameters<typeof createEntityController>) => { const response = await createEntityController(...args); setEntities(prev => [response.data, ...prev]); };
Pattern 3: With Parameters (versioned endpoints)
TypeScript// UPDATE with parameters - use correct args index const updateEntity = async (...args: Parameters<typeof updateEntityController>) => { const response = await updateEntityController(...args); const nArray = updateArrayItem({ arr: entities.results, identification: args[1], // Second parameter is ID values: response.data, targetField: 'id', }); setEntities(prev => ({ ...prev, results: nArray })); }; // DELETE with parameters const deleteEntity = async (...args: Parameters<typeof deleteEntityController>) => { await deleteEntityController(...args); setEntities(prev => ({ ...prev, count: prev.count - 1, results: prev.results.filter(r => r.id !== args[1]), // Second parameter is ID })); };
Examples
Example 1: Basic CRUD (no parameters)
TypeScript// Controller: getAreas(), createArea(body), updateArea(id, params), deleteArea(id) // Model uses args[0] for ID in update/delete operations const updateArea = async (...args: Parameters<typeof updateAreaController>) => { const nArray = updateArrayItem({ arr: areas.results, identification: args[0], // First parameter is ID values: data, targetField: 'id', }); };
Example 2: With version parameter
TypeScript// Controller: getEntities(version, qs), createEntity(version, body), updateEntity(version, id, params) // Model uses args[1] for ID in update/delete operations const updateEntity = async (...args: Parameters<typeof updateEntityController>) => { const nArray = updateArrayItem({ arr: entities.results, identification: args[1], // Second parameter is ID values: data, targetField: 'id', }); };
Best Practices
- Always use
Parameters<typeof controllerFunction>for type safety - Generic error messages without entity names: "Não foi possível obter os dados"
- Success messages can include entity context: "Versão criada com sucesso"
- Use
defaultPaginationValuesfor paginated responses - Prepend new items to arrays/results:
[newItem, ...existing] - Return hook with consistent naming:
entityLoading,entities,getEntities
Common Pitfalls
- Don't hardcode parameter positions - analyze controller signature first
- Don't use specific entity names in error messages
- Don't forget to handle both paginated and non-paginated responses
- Don't skip the loading state management with try/catch/finally
- Don't forget count updates for paginated create/delete operations