Files
zod-backend/src/customer/entities/customer.entity.ts
2025-08-11 15:25:16 +03:00

126 lines
3.7 KiB
TypeScript

import {
BaseEntity,
Column,
CreateDateColumn,
Entity,
Generated,
JoinColumn,
OneToMany,
OneToOne,
PrimaryColumn,
UpdateDateColumn,
} from 'typeorm';
import { Card } from '~/card/entities';
import { CountryIso } from '~/common/enums';
import { Guardian } from '~/guardian/entities/guradian.entity';
import { Junior } from '~/junior/entities';
import { User } from '~/user/entities';
import { CustomerStatus, KycStatus } from '../enums';
@Entity('customers')
export class Customer extends BaseEntity {
@PrimaryColumn('uuid')
id!: string;
@Column('varchar', { length: 255, default: CustomerStatus.PENDING, name: 'customer_status' })
customerStatus!: CustomerStatus;
@Column('varchar', { length: 255, default: KycStatus.PENDING, name: 'kyc_status' })
kycStatus!: KycStatus;
@Column('text', { nullable: true, name: 'rejection_reason' })
rejectionReason!: string | null;
@Column('varchar', { length: 255, nullable: true, name: 'first_name' })
firstName!: string;
@Column('varchar', { length: 255, nullable: true, name: 'last_name' })
lastName!: string;
@Column('date', { nullable: true, name: 'date_of_birth' })
dateOfBirth!: Date;
@Column('varchar', { length: 255, nullable: true, name: 'national_id' })
nationalId!: string;
@Column('date', { nullable: true, name: 'national_id_expiry' })
nationalIdExpiry!: Date;
@Column('varchar', { length: 255, nullable: true, name: 'country_of_residence' })
countryOfResidence!: CountryIso;
@Column('varchar', { length: 255, nullable: true, name: 'source_of_income' })
sourceOfIncome!: string;
@Column('varchar', { length: 255, nullable: true, name: 'profession' })
profession!: string;
@Column('varchar', { length: 255, nullable: true, name: 'profession_type' })
professionType!: string;
@Column('boolean', { default: false, name: 'is_pep' })
isPep!: boolean;
@Column('varchar', { length: 255, nullable: true, name: 'gender' })
gender!: string;
@Column('boolean', { default: false, name: 'is_junior' })
isJunior!: boolean;
@Column('boolean', { default: false, name: 'is_guardian' })
isGuardian!: boolean;
@Column('int', { name: 'application_number' })
@Generated('increment')
applicationNumber!: number;
@Column('varchar', { name: 'user_id' })
userId!: string;
@Column('varchar', { name: 'country', length: 255, nullable: true })
country!: CountryIso;
@Column('varchar', { name: 'region', length: 255, nullable: true })
region!: string;
@Column('varchar', { name: 'city', length: 255, nullable: true })
city!: string;
@Column('varchar', { name: 'neighborhood', length: 255, nullable: true })
neighborhood!: string;
@Column('varchar', { name: 'street', length: 255, nullable: true })
street!: string;
@Column('varchar', { name: 'building', length: 255, nullable: true })
building!: string;
@OneToOne(() => User, (user) => user.customer, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'user_id' })
user!: User;
@OneToOne(() => Junior, (junior) => junior.customer, { cascade: true })
junior!: Junior;
@OneToOne(() => Guardian, (guardian) => guardian.customer, { cascade: true })
guardian!: Guardian;
// relation ship between customer and card
@OneToMany(() => Card, (card) => card.customer)
cards!: Card[];
// relationship between cards and their parent customer
@OneToMany(() => Card, (card) => card.parentCustomer)
childCards!: Card[];
@CreateDateColumn({ type: 'timestamp with time zone', default: () => 'CURRENT_TIMESTAMP', name: 'created_at' })
createdAt!: Date;
@UpdateDateColumn({ type: 'timestamp with time zone', default: () => 'CURRENT_TIMESTAMP', name: 'updated_at' })
updatedAt!: Date;
get fullName(): string {
return `${this.firstName} ${this.lastName}`;
}
}