Replies: 2 comments 2 replies
-
So if you want to exclude password, you should
May I give you a tip: Don't store sensitive data at a common entity like that. Put it in class Account {
@t.mongoId
public _id: string;
@t
public __v: number;
@t
@prop()
public email: string;
}
class AccountCredentials {
@prop()
public password?: string;
constructor(@t.primary.reference() public account: Account) {
}
} This way you do not "accidentally" expose this information. |
Beta Was this translation helpful? Give feedback.
-
Thanks Marc (@marcj)! I appreciate the reply. Ok. Now I understand. What I'm doing is writing a test suite for Typegoose, so that it shows Typegoose can work with @deepkit/type instead of class-transformer, because it seems, class-transformer is abandonware. So, the Account entity is just one for testing. I have the tests finished and passing now. IMHO, the intention should be that if the I think this makes for ugly code. Can you suggest anything else? class Account {
@t.mongoId.group(Group.public)
public _id: string;
@t.group(Group.public)
public __v: number;
@t.group(Group.public)
@prop()
public email: string;
@t.group(Group.confidential)
@prop()
public confidentialProperty?: string;
} The tip on not having the password property directly in the entity is a good one. I'll take you up on it in my regular apps. I've changed the property name to Thanks again. Scott |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
When using
plainToClass
with or without the group options, I seem to have difficulty understanding the intention of the library. I also looked at tests and the source code. I'm still very uncertain.So, I'll explain my situation. If I have the entity below (side note: this is also using Typegoose thus why the
@prop
decorators are there):and I use
plainToClass
without any grouping options, I get all properties. My thinking was, I should get all properties except the password.If I use
plainToClass
with thegroups
option, I get only thepassword
property.And, if do this.
If I use
plainToClass
without any group options, I get all properties exceptpassword
. This is how I thought it should work and seems correct to me.However, if I use
plainToClass
with thegroups
option, I get an empty object back. This doesn't make any sense to me and I tried the different group options (i.e. empty arrays, groupsExclude, etc). So, I believe my understanding about how @deepkit/type should be working is probably not completely understood, despite me reading the docs several times, looking at source code and tests (which btw, the options forplainToClass
aren't tested or I couldn't find it).What I'd like to see is, if I use
plainToClass
with no grouping options, I want all properties except the password. If I also add thegroups
option, then thepassword
property should also be given. If there is no value in the pojo forpassword
, it should give me a null value for the property.Can someone help me clarify my understanding?
Scott
Beta Was this translation helpful? Give feedback.
All reactions