This commit is contained in:
2024-11-26 13:19:48 +07:00
commit df875117b0
31 changed files with 1273 additions and 0 deletions

71
src/entity/users.ts Normal file
View File

@ -0,0 +1,71 @@
import bcrypt from 'bcryptjs';
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm';
import { Role } from '../types/role';
import { Status } from '../types/status';
@Entity('users')
export class User {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({
nullable: false,
unique: true,
length: 64
})
email: string;
@Column({
nullable: false,
length: 64,
select: false
})
password: string;
@Column({
nullable: false,
unique: true,
length: 64
})
username: string;
@Column({
nullable: true,
length: 64
})
name: string;
@Column({
nullable: false,
default: 'STAFF' as Role,
length: 30,
})
role: Role;
@Column({
nullable: false,
length: 64
})
status: Status;
@Column()
@CreateDateColumn()
created_at: Date;
@Column({ nullable: true })
@UpdateDateColumn()
updated_at: Date;
@Column({ nullable: true })
@DeleteDateColumn()
deleted_at: Date;
hashPassword() {
this.password = bcrypt.hashSync(this.password, 8);
}
checkIfPasswordMatch(unencryptedPassword: string) {
return bcrypt.compareSync(unencryptedPassword, this.password);
}
}

View File

@ -0,0 +1,71 @@
import bcrypt from 'bcryptjs';
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm';
import { Role } from '../types/role';
import { Status } from '../types/status';
@Entity('users')
export class User {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({
nullable: false,
unique: true,
length: 64
})
email: string;
@Column({
nullable: false,
length: 64,
select: false
})
password: string;
@Column({
nullable: false,
unique: true,
length: 64
})
username: string;
@Column({
nullable: true,
length: 64
})
name: string;
@Column({
nullable: false,
default: 'STAFF' as Role,
length: 30,
})
role: Role;
@Column({
nullable: false,
length: 64
})
status: Status;
@Column()
@CreateDateColumn()
created_at: Date;
@Column({ nullable: true })
@UpdateDateColumn()
updated_at: Date;
@Column({ nullable: true })
@DeleteDateColumn()
deleted_at: Date;
hashPassword() {
this.password = bcrypt.hashSync(this.password, 8);
}
checkIfPasswordMatch(unencryptedPassword: string) {
return bcrypt.compareSync(unencryptedPassword, this.password);
}
}

View File

@ -0,0 +1,71 @@
import bcrypt from 'bcryptjs';
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm';
import { Role } from '../types/role';
import { Status } from '../types/status';
@Entity('users')
export class User {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({
nullable: false,
unique: true,
length: 64
})
email: string;
@Column({
nullable: false,
length: 64,
select: false
})
password: string;
@Column({
nullable: false,
unique: true,
length: 64
})
username: string;
@Column({
nullable: true,
length: 64
})
name: string;
@Column({
nullable: false,
default: 'STAFF' as Role,
length: 30,
})
role: Role;
@Column({
nullable: false,
length: 64
})
status: Status;
@Column()
@CreateDateColumn()
created_at: Date;
@Column({ nullable: true })
@UpdateDateColumn()
updated_at: Date;
@Column({ nullable: true })
@DeleteDateColumn()
deleted_at: Date;
hashPassword() {
this.password = bcrypt.hashSync(this.password, 8);
}
checkIfPasswordMatch(unencryptedPassword: string) {
return bcrypt.compareSync(unencryptedPassword, this.password);
}
}