All files / src/users user.entity.ts

100% Statements 9/9
100% Branches 10/10
100% Functions 3/3
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 3610x                       51x 51x 51x 51x 51x 51x       1x       8x                    
export class User {
  id: string;
  email: string;
  name?: string;
  passwordHash: string;
  profileImage?: string;
  emailVerified: boolean;
  isActive: boolean;
  createdAt: Date;
  updatedAt: Date;
 
  constructor(partial: Partial<User>) {
    Object.assign(this, partial);
    this.id = this.id || this.generateId();
    this.emailVerified = this.emailVerified ?? false;
    this.isActive = this.isActive ?? true;
    this.createdAt = this.createdAt || new Date();
    this.updatedAt = this.updatedAt || new Date();
  }
 
  private generateId(): string {
    return Math.random().toString(36).substr(2, 9) + Date.now().toString(36);
  }
 
  toProfile() {
    return {
      id: this.id,
      email: this.email,
      name: this.name,
      profileImage: this.profileImage,
      emailVerified: this.emailVerified,
      createdAt: this.createdAt,
    };
  }
}