nartc/nest-mean

Suggestion

okbriel opened this issue · 3 comments

I don't like the way automapper-ts is used for just a simple transformation on the resulting Object from Mongo. You can use the toObject transform property:
toObject

The automapper-ts project is good but I find that mongoose toObject cover most if not all use cases.

nartc commented

I agreed. At the point of making this tutorial, I wasn't aware of toObject. You have a code snippet for me to look at regarding this tutorial?

I also don't use typegoose on my project, I found it very unreliable and missing key features.

new mongoose.Schema({
    profiles: [{
        _id: false,
        login: { type: String, required: true, uppercase: true },
        type: { type: String, required: true, uppercase: true },
    }],
    password: { type: String, required: true },
},
{
    toObject: {
        transform: (doc, ret) => {
            delete ret.password;
        },
    },
});
nartc commented

Understandable. I'll look into this more.

Don't have my Mac with me so can't really double-check anything on Typegoose side. I might have to redo this and strip Typegoose + AutoMapper.