Files
zod-backend/src/customer/entities/customer.entity.ts
Abdalhamid Alhamad 110a6fb0ee refactor: remove address fields from customer entity and related services
- Removed address-related fields from Customer entity, DTOs, and services to streamline KYC process.
- Updated KYC initiation and customer update logic to default to Saudi Arabia for country and use fixed address values.
- Added migration to drop address columns from the database.
2025-12-18 12:35:32 +03:00

121 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, Gender, 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('boolean', { default: false, name: 'is_pep' })
isPep!: boolean;
@Column('varchar', { length: 255, nullable: true, name: 'gender' })
gender!: Gender;
@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;
// KYC-specific fields
@Column('varchar', { length: 255, nullable: true, name: 'neoleap_external_customer_id' })
neoleapExternalCustomerId!: string | null;
@Column('varchar', { length: 100, nullable: true, name: 'job_sector' })
jobSector!: string | null;
@Column('varchar', { length: 255, nullable: true, name: 'employer' })
employer!: string | null;
@Column('varchar', { length: 100, nullable: true, name: 'income_source' })
incomeSource!: string | null;
@Column('varchar', { length: 100, nullable: true, name: 'job_category' })
jobCategory!: string | null;
@Column('varchar', { length: 100, nullable: true, name: 'income_range' })
incomeRange!: string | null;
@Column('varchar', { length: 20, nullable: true, name: 'mobile_number' })
mobileNumber!: string | null;
@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}`;
}
}