-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
👩💻 공유 사항
가상필드 혹은 getter, setter 선언 방법입니다.
@ModelOptions({autoIndex: true, toJSON: {virtuals: true}}) //모든 필드에 인덱싱, 반환할때 get있는 가상필드 포함
export class Customer extends Document {
@Prop()
public firstName: string;
@Prop()
public lastName: string;
@Prop({unique: true})
public email: string;
@Prop()
public phone: string;
@Prop()
public address: string;
@Prop()
public description: string;
// this will create a virtual property called 'fullName'
public get fullName() {
return `${this.firstName} ${this.lastName}`;
}
public set fullName(full:string) {
const [firstName, lastName] = full.split(' ');
this.firstName = firstName;
this.lastName = lastName;
}
}메소드 선언 방법입니다.
@Schema()
export class Auth extends Document {
...
validatePassword: Function;
}
export const AuthSchema = SchemaFactory.createForClass(Auth);
AuthSchema.methods.validatePassword = async function (password: string): Promise<boolean> {
return bcrypt.compareAsync(password, this.password);
};✅ 참고 사항
공유할 내용, 스크린샷 등을 넣어 주세요.
- 추가적인 공유가 필요한 사항은 Comment
Metadata
Metadata
Assignees
Labels
No labels