import { BeforeInsert, Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn, } from 'typeorm'; @Entity() @Index(['phone', 'used']) export class OTP { @PrimaryGeneratedColumn() id!: number; @Index() @Column({ type: 'varchar', length: 11, nullable: false, }) phone!: string; @Column({ type: 'varchar', nullable: false, }) code!: string; @CreateDateColumn() createdAt!: Date; @Index() @Column({ type: 'timestamptz' }) expiresAt!: Date; @Column({ type: 'boolean', default: false }) used!: boolean; @BeforeInsert() setExpiry() { this.expiresAt = new Date(Date.now() + 2 * 60 * 1000); } }