mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-03-10 19:51:46 +00:00
- 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.
121 lines
3.7 KiB
TypeScript
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}`;
|
|
}
|
|
}
|