Files
zod-backend/src/user/entities/user.entity.ts
2025-01-13 11:43:28 +03:00

81 lines
2.3 KiB
TypeScript

import {
BaseEntity,
Column,
CreateDateColumn,
Entity,
OneToMany,
OneToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { Notification } from '~/common/modules/notification/entities';
import { Otp } from '~/common/modules/otp/entities';
import { Customer } from '~/customer/entities/customer.entity';
import { Document } from '~/document/entities';
import { Roles } from '../../auth/enums';
import { Device } from './device.entity';
@Entity('users')
export class User extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column('varchar', { length: 255, nullable: true, name: 'email' })
email!: string;
@Column('varchar', { length: 255, name: 'phone_number', nullable: true })
phoneNumber!: string;
@Column('varchar', { length: 10, name: 'country_code', nullable: true })
countryCode!: string;
@Column('varchar', { length: 255, name: 'password', nullable: true })
password!: string;
@Column('varchar', { length: 255, name: 'salt', nullable: true })
salt!: string;
@Column('varchar', { length: 255, nullable: true, name: 'google_id' })
googleId!: string;
@Column('varchar', { length: 255, nullable: true, name: 'apple_id' })
appleId!: string;
@Column('boolean', { default: false, name: 'is_phone_verified' })
isPhoneVerified!: boolean;
@Column('boolean', { default: false, name: 'is_email_verified' })
isEmailVerified!: boolean;
@Column('boolean', { default: false, name: 'is_profile_completed' })
isProfileCompleted!: boolean;
@Column('text', { nullable: true, array: true, name: 'roles' })
roles!: Roles[];
@OneToMany(() => Otp, (otp) => otp.user)
otp!: Otp[];
@OneToOne(() => Customer, (customer) => customer.user, { cascade: true, eager: true })
customer!: Customer;
@OneToMany(() => Device, (device) => device.user)
devices!: Device[];
@OneToMany(() => Notification, (notification) => notification.user)
notifications!: Notification[];
@OneToMany(() => Document, (document) => document.createdBy)
createdDocuments!: Document[];
@CreateDateColumn({ name: 'created_at', type: 'timestamp with time zone' })
createdAt!: Date;
@UpdateDateColumn({ name: 'updated_at', type: 'timestamp with time zone' })
updatedAt!: Date;
get isPasswordSet(): boolean {
return !!this.password;
}
}