30 lines
856 B
TypeScript
30 lines
856 B
TypeScript
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index } from 'typeorm';
|
|
|
|
@Entity({ name: 'referral_codes', schema: 'public' })
|
|
export class ReferralCode {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id!: string;
|
|
|
|
// FK to public.tenants.id — one code per tenant
|
|
@Column({ name: 'tenant_id', type: 'varchar', unique: true })
|
|
tenantId!: string;
|
|
|
|
// The admin user who owns this code
|
|
@Column({ name: 'user_id', type: 'varchar' })
|
|
userId!: string;
|
|
|
|
// e.g. "IT0-ACM-X9K2"
|
|
@Column({ type: 'varchar', length: 20, unique: true })
|
|
@Index()
|
|
code!: string;
|
|
|
|
@Column({ name: 'click_count', type: 'int', default: 0 })
|
|
clickCount!: number;
|
|
|
|
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
|
createdAt!: Date;
|
|
|
|
@UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
|
|
updatedAt!: Date;
|
|
}
|