PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 13, 2022

[FIXED] How to migrate some route DTO object in NestJ?

 April 13, 2022     javascript, migration, nestjs, node.js, rest     No comments   

Issue

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!


Solution

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.



Answered By - Alex Dumitru
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing