I use NestJS and my app have some changes in the DTO objects that is expects to receive in the controller. The client side is a mobile app and I can’t force the users to update version, so I might get DTO objects that might not be in the updated version that my server side expects to receive.
What I want to do is to take the object I get and if I see the object is received from older version of the client side then I want this object to be migrated to the updated object type.
What is the best approach to do this?
Thanks in advance!
CodePudding user response:
A simple solution can be adding a field that indicates that the recived object is the DTO's updated version, check if that field exist or not, then apply the consequent logic.
Another way is to use the API versioning, you can find how to use it in the NestJS official documentation. This one I think is a better approach, this because if in the future you want to update again the DTO, you have only to create another controller version.