Files
zod-backend/src/user/entities/user.entity.ts

112 lines
3.3 KiB
TypeScript

import {
BaseEntity,
Column,
CreateDateColumn,
Entity,
JoinColumn,
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';
import { UserAuthToken } from './user-auth-token.entity';
@Entity('users')
export class User extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column('varchar', { length: 255, name: 'first_name', nullable: false })
firstName!: string;
@Column('varchar', { length: 255, name: 'last_name', nullable: false })
lastName!: string;
@Column('varchar', { length: 255, name: 'email', nullable: true, unique: true })
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({ name: 'is_email_enabled', default: false })
isEmailEnabled!: boolean;
@Column({ name: 'is_push_enabled', default: false })
isPushEnabled!: boolean;
@Column({ name: 'is_sms_enabled', default: false })
isSmsEnabled!: 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[];
@OneToMany(() => UserAuthToken, (token) => token.user)
registrationTokens!: UserAuthToken[];
@Column('varchar', { name: 'profile_picture_id', nullable: true })
profilePictureId!: string;
@OneToOne(() => Document, (document) => document.userPicture, { cascade: true, nullable: true })
@JoinColumn({ name: 'profile_picture_id' })
profilePicture!: 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;
}
get fullPhoneNumber(): string {
return `${this.countryCode}${this.phoneNumber}`;
}
}