File

src/entity/user.entity.ts

Index

Properties
Methods

Properties

birthDate
Type : Date | null
Decorators :
@Column({nullable: true})
birthName
Type : string | null
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
courses
Type : Course[]
Decorators :
@ManyToMany(undefined)
@JoinTable()
created
Type : Date
Decorators :
@CreateDateColumn()
email
Type : string | null
Decorators :
@Column({nullable: true, length: 255, unique: true, charset: 'utf8', collation: 'utf8_hungarian_ci'})
firstName
Type : string | null
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
genderIdentity
Type : string | null
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
generatedID
Type : string | null
Decorators :
@Column({nullable: true, length: 255, unique: true})
group
Type : Group | null
Decorators :
@ManyToOne(undefined, undefined, {onUpdate: 'CASCADE', onDelete: 'CASCADE'})
groupId
Type : number
Decorators :
@Column({unsigned: true})
id
Type : number
Decorators :
@PrimaryGeneratedColumn({unsigned: true})
isActive
Type : Boolean
Decorators :
@Column({nullable: false, default: true})
jobGroup
Type : string | null
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
lastName
Type : string | null
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
modified
Type : Date
Decorators :
@UpdateDateColumn()
organizationalUnit
Type : string | null
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
password
Type : string | null
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
rank
Type : string | null
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
Private tempPassword
Type : string
userCourse
Type : UserCourse
Decorators :
@OneToMany(undefined, undefined, {onDelete: 'CASCADE', onUpdate: 'CASCADE', cascade: true})
userUniqueField
Type : UserUniqueFiled
Decorators :
@OneToMany(undefined, undefined, {onDelete: 'CASCADE', onUpdate: 'CASCADE', cascade: true})
workStartDate
Type : Date | null
Decorators :
@Column({nullable: true})

Methods

afterLoad
afterLoad()
Decorators :
@AfterLoad()
Returns : void
beforeInsert
beforeInsert()
Decorators :
@BeforeInsert()
Returns : void
beforeUpdate
beforeUpdate()
Decorators :
@BeforeUpdate()
Returns : void
toJSON
toJSON()
Returns : { id: number; email: string; firstName: string; lastName: string; rank: string; birthName: string...
import {
  Column,
  Entity,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  BeforeInsert,
  BeforeUpdate,
  AfterLoad,
  ManyToOne,
  ManyToMany,
  JoinTable,
  OneToMany,
} from "typeorm";
import * as bcrypt from "bcryptjs";
import { Group } from "./group.entity";
import { Course } from "./course.entity";
import { UserUniqueFiled } from "./user-unique-field.entity";
import { UserCourse } from "./user-course.entity";

@Entity()
export class User {
  @PrimaryGeneratedColumn({
    unsigned: true,
  })
  id: number;

  @Column({
    nullable: true,
    length: 255,
    unique: true,
    charset: 'utf8', collation: 'utf8_hungarian_ci'
  })
  email: string | null;

  @Column({
    nullable: true,
    length: 255,
    unique: true,
  })
  generatedID: string | null;

  @Column({
    nullable: true,
    length: 255,
    charset: 'utf8', collation: 'utf8_hungarian_ci'
  })
  firstName: string | null;
  @Column({
    nullable: true,
    length: 255,
    charset: 'utf8', collation: 'utf8_hungarian_ci'
  })
  lastName: string | null;

  @Column({
    nullable: true,
    length: 255,
    charset: 'utf8', collation: 'utf8_hungarian_ci'
  })
  password: string | null;

  @Column({
    nullable: true,
    length: 255,
    charset: 'utf8', collation: 'utf8_hungarian_ci'
  })
  jobGroup: string | null;

  @Column({
    nullable: true,
  })
  workStartDate: Date | null;
  @Column({
    nullable: true,
    length: 255,
    charset: 'utf8', collation: 'utf8_hungarian_ci'
  })
  genderIdentity: string | null;

  @Column({
    nullable: true,
    length: 255,
    charset: 'utf8', collation: 'utf8_hungarian_ci'
  })
  birthName: string | null;

  @Column({
    nullable: true,
    length: 255,
    charset: 'utf8', collation: 'utf8_hungarian_ci'
  })
  rank: string | null;
  @Column({
    nullable: true,
    length: 255,
    charset: 'utf8', collation: 'utf8_hungarian_ci'
  })
  organizationalUnit: string | null;

  @Column({
    nullable: true,
  })
  birthDate: Date | null;

  @Column({
    nullable: false,
    default: true,
  })
  isActive: Boolean;

  @CreateDateColumn()
  created: Date;

  @UpdateDateColumn()
  modified: Date;

  @BeforeInsert()
  beforeInsert() {
    if (
      this.password !== undefined &&
      this.password !== null &&
      this.password !== ""
    ) {
      this.password = bcrypt.hashSync(this.password);
    }
  }

  @BeforeUpdate()
  beforeUpdate() {
    if (this.tempPassword !== this.password) {
      this.password = bcrypt.hashSync(this.password);
    }
  }
  private tempPassword: string;

  @AfterLoad()
  afterLoad(): void {
    this.tempPassword = this.password;
  }

  @ManyToOne(
    (type) => Group,
    (group) => group.users,
    { onUpdate: "CASCADE", onDelete: "CASCADE" }
  )
  group: Group | null;

  @Column({
    unsigned: true,
  })
  groupId: number;

  @ManyToMany(() => Course)
  @JoinTable()
  courses: Course[];

  @OneToMany(type => UserUniqueFiled, userUniqueField => userUniqueField.user, { onDelete: 'CASCADE', onUpdate: 'CASCADE', cascade: true })
  userUniqueField: UserUniqueFiled;

  @OneToMany(type => UserCourse, userCourse => userCourse.user, { onDelete: 'CASCADE', onUpdate: 'CASCADE', cascade: true })
  userCourse: UserCourse;

  toJSON() {
    return {
      id: this.id,
      email: this.email,
      firstName: this.firstName,
      lastName: this.lastName,
      rank: this.rank,
      birthName: this.birthName,
      genderIdentity: this.genderIdentity,
      group: this.group,
      groupId: this.groupId,
      birthDate: this.birthDate !== null ? Math.round(this.birthDate.getTime() / 1000) : null,
      workStartDate: this.workStartDate !== null ? Math.round(this.workStartDate.getTime() / 1000) : null,
      jobGroup: this.jobGroup,
      isActive: this.isActive,
      courses: this.courses,
      organizationalUnit: this.organizationalUnit,
      generatedID: this.generatedID,
      userUniqueField: this.userUniqueField,
      created: Math.round(this.created.getTime() / 1000),
      modified: Math.round(this.modified.getTime() / 1000),
    };
  }
}

result-matching ""

    No results matching ""