55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
|
|
|
@Entity('invitation_codes')
|
|
export class InvitationCode {
|
|
@PrimaryGeneratedColumn({ type: 'bigint' })
|
|
id: bigint;
|
|
|
|
@Index({ unique: true })
|
|
@Column({ type: 'char', length: 64 })
|
|
code_hash: string;
|
|
|
|
@Column({ type: 'varchar', length: 20 })
|
|
code_prefix: string;
|
|
|
|
@Column({ type: 'int', unsigned: true, default: 1 })
|
|
max_uses: number;
|
|
|
|
@Column({ type: 'int', unsigned: true, default: 0 })
|
|
used_count: number;
|
|
|
|
@Column({ type: 'datetime', nullable: true })
|
|
expires_at?: Date | null;
|
|
|
|
@Column({ type: 'enum', enum: ['active', 'revoked'], default: 'active' })
|
|
status: 'active' | 'revoked';
|
|
|
|
@Column({ type: 'varchar', length: 255, nullable: true })
|
|
note?: string | null;
|
|
|
|
@Column({ type: 'bigint', nullable: true })
|
|
created_by?: bigint | null;
|
|
|
|
@CreateDateColumn({ type: 'datetime' })
|
|
created_at: Date;
|
|
}
|
|
|
|
@Entity('invitation_code_usages')
|
|
@Index(['invitation_code_id', 'user_id'], { unique: true })
|
|
export class InvitationCodeUsage {
|
|
@PrimaryGeneratedColumn({ type: 'bigint' })
|
|
id: bigint;
|
|
|
|
@Column({ type: 'bigint' })
|
|
invitation_code_id: bigint;
|
|
|
|
@Column({ type: 'bigint' })
|
|
user_id: bigint;
|
|
|
|
@Column({ type: 'varchar', length: 100 })
|
|
email: string;
|
|
|
|
@CreateDateColumn({ type: 'datetime' })
|
|
used_at: Date;
|
|
}
|