How to realize the DTO of the return value of a function

define a database model User

interface User {
    id: string,
    name: string,
    xxxx: string,
}

define a DTO UserDTO

interface UserDTO {
    id: string,
    name: string,
}

defines a method to get a user.
generally, if we do not want to expose all the information, we will fix the exposed attribute (id, name).


async function getUser(){
    const user = await UserService.findOne();
    return {
        id: user.id,
        name: user.name,
    };
}
// res= { id, name }

but the above writing is not suitable for automated scenarios, and I want to use the decorator to achieve the following functions.

@ReturnDto(UserDTO)
async function getUser({
    const user = await UserService.findOne();
    return user;
}
// res= { id, name }

I have tried a lot of methods, but there is still no way to modify it while getting the return value of the function asynchronously.
can you tell me how to implement it easily?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be09f9-398ce.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be09f9-398ce.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?