Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

Decide what DTO design pattern class-validation is optimizing for #6

Open
ben-ryder opened this issue Feb 6, 2022 · 0 comments
Open
Labels
discovery more information is needed documentation Improvements or additions to documentation package/class-validation issues related to @kangojs/class-validation work item A work item/ticket rather than an issue

Comments

@ben-ryder
Copy link
Owner

ben-ryder commented Feb 6, 2022

In a project using class-validation I'm facing a design pattern decision/question about the use of "DTO" classes.

Right now in that project DTO classes exist and are used to describe & validate request data. The same DTO classes are also used to describe the data passed from controllers -> business logic services -> database services.

The issue is my request data shape is now diverging from the data shape required by the database service. This means I now need multiple "DTO" classes for a single action:

  • one for validating request data at the controller layer and describing the interface between the controller and business logic service
  • one for describing the interface between the business logic layer and database service layer

This is fine, but I'm finding it somewhat confuses the use of the phrase "DTOs". My solution so far has been to now have a distinction between "shapes" and "dtos":

  • "Shapes" are classes defining the request data shape and are decorated with class-validator decorators
  • "DTOs" are classes that are purely for transferring data

None of this really relates to class-validation too much, however I'm thinking that it could be worth while removing all references to "DTOs" from class-validation.

@ben-ryder ben-ryder added documentation Improvements or additions to documentation discovery more information is needed work item A work item/ticket rather than an issue package/class-validation issues related to @kangojs/class-validation labels Feb 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
discovery more information is needed documentation Improvements or additions to documentation package/class-validation issues related to @kangojs/class-validation work item A work item/ticket rather than an issue
Projects
None yet
Development

No branches or pull requests

1 participant