Services return raw database entities directly, exposing internal database structure to API consumers. This creates tight coupling between database schema and API contracts, risks exposing sensitive fields, and makes it difficult to add computed fields or transformations. Any database schema change becomes a breaking API change.
Create dedicated response DTOs for all service methods with proper field mapping. Use class-transformer decorators for entity to DTO transformation. Implement @Exclude() for sensitive fields and @Expose() for computed properties. Ensure all API responses use DTOs rather than entities, providing a stable API contract independent of database structure.
Services return raw database entities directly, exposing internal database structure to API consumers. This creates tight coupling between database schema and API contracts, risks exposing sensitive fields, and makes it difficult to add computed fields or transformations. Any database schema change becomes a breaking API change.
Create dedicated response DTOs for all service methods with proper field mapping. Use
class-transformerdecorators for entity to DTO transformation. Implement@Exclude()for sensitive fields and@Expose()for computed properties. Ensure all API responses use DTOs rather than entities, providing a stable API contract independent of database structure.