src/entity/user.entity.ts
Properties |
Methods |
birthDate |
Type : Date | null
|
Decorators :
@Column({nullable: true})
|
Defined in src/entity/user.entity.ts:104
|
birthName |
Type : string | null
|
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
|
Defined in src/entity/user.entity.ts:86
|
courses |
Type : Course[]
|
Decorators :
@ManyToMany(undefined)
|
Defined in src/entity/user.entity.ts:156
|
created |
Type : Date
|
Decorators :
@CreateDateColumn()
|
Defined in src/entity/user.entity.ts:113
|
Type : string | null
|
Decorators :
@Column({nullable: true, length: 255, unique: true, charset: 'utf8', collation: 'utf8_hungarian_ci'})
|
Defined in src/entity/user.entity.ts:34
|
firstName |
Type : string | null
|
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
|
Defined in src/entity/user.entity.ts:48
|
genderIdentity |
Type : string | null
|
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
|
Defined in src/entity/user.entity.ts:79
|
generatedID |
Type : string | null
|
Decorators :
@Column({nullable: true, length: 255, unique: true})
|
Defined in src/entity/user.entity.ts:41
|
group |
Type : Group | null
|
Decorators :
@ManyToOne(undefined, undefined, {onUpdate: 'CASCADE', onDelete: 'CASCADE'})
|
Defined in src/entity/user.entity.ts:147
|
groupId |
Type : number
|
Decorators :
@Column({unsigned: true})
|
Defined in src/entity/user.entity.ts:152
|
id |
Type : number
|
Decorators :
@PrimaryGeneratedColumn({unsigned: true})
|
Defined in src/entity/user.entity.ts:26
|
isActive |
Type : Boolean
|
Decorators :
@Column({nullable: false, default: true})
|
Defined in src/entity/user.entity.ts:110
|
jobGroup |
Type : string | null
|
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
|
Defined in src/entity/user.entity.ts:68
|
lastName |
Type : string | null
|
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
|
Defined in src/entity/user.entity.ts:54
|
modified |
Type : Date
|
Decorators :
@UpdateDateColumn()
|
Defined in src/entity/user.entity.ts:116
|
organizationalUnit |
Type : string | null
|
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
|
Defined in src/entity/user.entity.ts:99
|
password |
Type : string | null
|
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
|
Defined in src/entity/user.entity.ts:61
|
rank |
Type : string | null
|
Decorators :
@Column({nullable: true, length: 255, charset: 'utf8', collation: 'utf8_hungarian_ci'})
|
Defined in src/entity/user.entity.ts:93
|
Private tempPassword |
Type : string
|
Defined in src/entity/user.entity.ts:135
|
userCourse |
Type : UserCourse
|
Decorators :
@OneToMany(undefined, undefined, {onDelete: 'CASCADE', onUpdate: 'CASCADE', cascade: true})
|
Defined in src/entity/user.entity.ts:162
|
userUniqueField |
Type : UserUniqueFiled
|
Decorators :
@OneToMany(undefined, undefined, {onDelete: 'CASCADE', onUpdate: 'CASCADE', cascade: true})
|
Defined in src/entity/user.entity.ts:159
|
workStartDate |
Type : Date | null
|
Decorators :
@Column({nullable: true})
|
Defined in src/entity/user.entity.ts:73
|
afterLoad |
afterLoad()
|
Decorators :
@AfterLoad()
|
Defined in src/entity/user.entity.ts:138
|
Returns :
void
|
beforeInsert |
beforeInsert()
|
Decorators :
@BeforeInsert()
|
Defined in src/entity/user.entity.ts:119
|
Returns :
void
|
beforeUpdate |
beforeUpdate()
|
Decorators :
@BeforeUpdate()
|
Defined in src/entity/user.entity.ts:130
|
Returns :
void
|
toJSON |
toJSON()
|
Defined in src/entity/user.entity.ts:164
|
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),
};
}
}