Files
docmost/server/src/core/user/entities/user.entity.ts
T
Philipinho f11f9f6210 Add new page module and services; refactor existing entities
- Introduced a new page module with associated services.
- Refactored TypeORM entities in user and workspace modules.
2023-08-22 19:48:57 +01:00

76 lines
1.6 KiB
TypeScript

import {
BeforeInsert,
Column,
CreateDateColumn,
Entity,
OneToMany,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import * as bcrypt from 'bcrypt';
import { Workspace } from '../../workspace/entities/workspace.entity';
import { WorkspaceUser } from '../../workspace/entities/workspace-user.entity';
import { Page } from '../../page/entities/page.entity';
@Entity('users')
export class User {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ length: 255, nullable: true })
name: string;
@Column({ length: 255, unique: true })
email: string;
@Column({ nullable: true })
emailVerifiedAt: Date;
@Column()
password: string;
@Column({ nullable: true })
avatarUrl: string;
@Column({ length: 100, nullable: true })
locale: string;
@Column({ length: 300, nullable: true })
timezone: string;
@Column({ type: 'jsonb', nullable: true })
settings: any;
@Column({ nullable: true })
lastLoginAt: Date;
@Column({ length: 100, nullable: true })
lastLoginIp: string;
@CreateDateColumn()
createdAt: Date;
@UpdateDateColumn()
updatedAt: Date;
@OneToMany(() => Workspace, (workspace) => workspace.creator)
workspaces: Workspace[];
@OneToMany(() => WorkspaceUser, (workspaceUser) => workspaceUser.user)
workspaceUser: WorkspaceUser[];
@OneToMany(() => Page, (page) => page.creator)
createdPages;
toJSON() {
delete this.password;
return this;
}
@BeforeInsert()
async hashPassword() {
const saltRounds = 12;
this.password = await bcrypt.hash(this.password, saltRounds);
}
}