mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 05:42:27 +00:00
90 lines
2.7 KiB
TypeScript
90 lines
2.7 KiB
TypeScript
import {
|
|
Column,
|
|
CreateDateColumn,
|
|
Entity,
|
|
Index,
|
|
JoinColumn,
|
|
ManyToOne,
|
|
OneToMany,
|
|
PrimaryGeneratedColumn,
|
|
UpdateDateColumn,
|
|
} from 'typeorm';
|
|
import { Customer } from '~/customer/entities';
|
|
import { CardColors, CardIssuers, CardScheme, CardStatus, CardStatusDescription, CustomerType } from '../enums';
|
|
import { Account } from './account.entity';
|
|
import { Transaction } from './transaction.entity';
|
|
|
|
@Entity('cards')
|
|
export class Card {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id!: string;
|
|
|
|
@Index({ unique: true })
|
|
@Column({ name: 'card_reference', nullable: false, type: 'varchar' })
|
|
cardReference!: string;
|
|
|
|
@Index({ unique: true })
|
|
@Column({ name: 'vpan', nullable: false, type: 'varchar' })
|
|
vpan!: string;
|
|
|
|
@Column({ length: 6, name: 'first_six_digits', nullable: false, type: 'varchar' })
|
|
firstSixDigits!: string;
|
|
|
|
@Column({ length: 4, name: 'last_four_digits', nullable: false, type: 'varchar' })
|
|
lastFourDigits!: string;
|
|
|
|
@Column({ type: 'varchar', nullable: false })
|
|
expiry!: string;
|
|
|
|
@Column({ type: 'varchar', nullable: false, name: 'customer_type' })
|
|
customerType!: CustomerType;
|
|
|
|
@Column({ type: 'varchar', nullable: false, default: CardColors.BLUE })
|
|
color!: CardColors;
|
|
|
|
@Column({ type: 'varchar', nullable: false, default: CardStatus.PENDING })
|
|
status!: CardStatus;
|
|
|
|
@Column({ type: 'varchar', nullable: false, default: CardStatusDescription.PENDING_ACTIVATION })
|
|
statusDescription!: CardStatusDescription;
|
|
|
|
@Column({ type: 'decimal', precision: 10, scale: 2, default: 0.0, name: 'limit' })
|
|
limit!: number;
|
|
|
|
@Column({ type: 'varchar', nullable: false, default: CardScheme.VISA })
|
|
scheme!: CardScheme;
|
|
|
|
@Column({ type: 'varchar', nullable: false })
|
|
issuer!: CardIssuers;
|
|
|
|
@Column({ type: 'uuid', name: 'customer_id', nullable: false })
|
|
customerId!: string;
|
|
|
|
@Column({ type: 'uuid', name: 'parent_id', nullable: true })
|
|
parentId?: string;
|
|
|
|
@Column({ type: 'uuid', name: 'account_id', nullable: false })
|
|
accountId!: string;
|
|
|
|
@ManyToOne(() => Customer, (customer) => customer.childCards)
|
|
@JoinColumn({ name: 'parent_id' })
|
|
parentCustomer?: Customer;
|
|
|
|
@ManyToOne(() => Customer, (customer) => customer.cards, { onDelete: 'CASCADE' })
|
|
@JoinColumn({ name: 'customer_id' })
|
|
customer!: Customer;
|
|
|
|
@ManyToOne(() => Account, (account) => account.cards, { onDelete: 'CASCADE' })
|
|
@JoinColumn({ name: 'account_id' })
|
|
account!: Account;
|
|
|
|
@OneToMany(() => Transaction, (transaction) => transaction.card, { cascade: true })
|
|
transactions!: Transaction[];
|
|
|
|
@CreateDateColumn({ name: 'created_at', type: 'timestamp with time zone' })
|
|
createdAt!: Date;
|
|
|
|
@UpdateDateColumn({ type: 'timestamp with time zone', name: 'updated_at' })
|
|
updatedAt!: Date;
|
|
}
|