Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

using dto in node js

//Dto data transfer object  protect your API clients from changes made on the server
//using function base approach
 function userDto(user, postsCount){
   return {
       id:user._id
       name: user.name,
       email: user.email,
       postsCount: postsCount
     }
 }
//using class based approach
//ackenddtosuser-dto.js
class UserDto {
    id;
    phone;
    activated;
    createdAt;

    constructor(user) {
        this.id = user._id;
        this.phone = user.phone;
        this.activated = user.activated;
        this.createdAt = user.createdAt;
    }
}
module.exports = UserDto;
 
PREVIOUS NEXT
Tagged: #dto #node #js
ADD COMMENT
Topic
Name
4+9 =