AI Skill Report Card
Creating TypeScript PATCH Controllers
Quick Start15 / 15
TypeScriptexport const updateEntityController = async ( id: Namespace.Entity.Entity['id'], params: Namespace.Entity.UpdateEntityParams, ): Promise<AxiosResponse<Namespace.Entity.Entity, any>> => { const url = `/api/entity/${id}/`; const instance = genRequestInstance(); try { const response = await instance.patch(url, params); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Recommendation▾
Replace the checklist workflow with a clear step-by-step process that explains the actual methodology for creating PATCH controllers
Workflow10 / 15
Progress:
- Determine entity name and namespace
- Check if additional URL parameters are needed (beyond entity ID)
- Verify required types exist in typings.d.ts
- Generate JSDoc comments
- Create controller method with proper signature
- Build URL with parameters
- Add error handling
Recommendation▾
Add concrete templates or frameworks section with reusable patterns for different controller scenarios
Examples20 / 20
Example 1 - Simple Entity Update: Input: Create update controller for "User" entity Output:
TypeScript/** * Updates a user entity * @param id - The user ID to update * @param params - The update parameters * @returns Promise with the updated user data * @throws Error if update fails or user not found */ export const updateUserController = async ( id: User.User['id'], params: User.UpdateUserParams, ): Promise<AxiosResponse<User.User, any>> => { const url = `/api/user/${id}/`; const instance = genRequestInstance(); try { const response = await instance.patch(url, params); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Example 2 - With Additional Parameters: Input: Create update controller for "Product" entity with "store" parameter Output:
TypeScript/** * Updates a product entity within a specific store * @param storeId - The store ID containing the product * @param id - The product ID to update * @param params - The update parameters * @returns Promise with the updated product data * @throws Error if update fails or product not found */ export const updateProductController = async ( storeId: Store.Store['id'], id: Product.Product['id'], params: Product.UpdateProductParams, ): Promise<AxiosResponse<Product.Product, any>> => { const url = `/api/store/${storeId}/product/${id}/`; const instance = genRequestInstance(); try { const response = await instance.patch(url, params); return response; } catch (error) { console.error('Erro na requisição:', error); return Promise.reject(error); } };
Recommendation▾
Include edge cases like handling validation errors, network failures, and authentication issues with specific code examples
Best Practices
- Method naming: Use
update{EntityName}Controllerpattern - Parameter order: Additional path params first, then entity ID, then update params
- URL structure: Follow REST conventions
/api/{namespace}/{param}/{entity}/{id}/ - Types: Always reference types from typings.d.ts using namespace notation
- JSDoc: Include @param for all parameters, @returns, and @throws
- Error handling: Use try-catch with console.error and Promise.reject
- Response typing: Use
AxiosResponse<EntityType, any>for return type
Common Pitfalls
- Missing types: Don't proceed without confirming UpdateEntityParams and Entity types exist
- Incorrect URL: Ensure trailing slash in URL path
- Wrong parameter order: Always put path parameters before entity ID
- Missing imports: Remember to import genRequestInstance from the request utilities
- Inconsistent naming: Stick to the established camelCase pattern for method names