|
|
import { |
|
|
Entity, |
|
|
PrimaryGeneratedColumn, |
|
|
Column, |
|
|
CreateDateColumn, |
|
|
UpdateDateColumn, |
|
|
ManyToOne, |
|
|
Index, |
|
|
} from 'typeorm'; |
|
|
import { User } from './User'; |
|
|
|
|
|
@Entity('api_keys') |
|
|
@Index(['key', 'isActive']) |
|
|
export class ApiKey { |
|
|
@PrimaryGeneratedColumn('uuid') |
|
|
id: string; |
|
|
|
|
|
@Column({ unique: true }) |
|
|
key: string; |
|
|
|
|
|
@ManyToOne(() => User, (user) => user.apiKeys) |
|
|
user: User; |
|
|
|
|
|
@Column() |
|
|
userId: string; |
|
|
|
|
|
@Column({ default: true }) |
|
|
isActive: boolean; |
|
|
|
|
|
@Column({ nullable: true }) |
|
|
rateLimit?: number; |
|
|
|
|
|
@Column({ nullable: true }) |
|
|
expiresAt?: Date; |
|
|
|
|
|
@Column({ default: 0 }) |
|
|
usageCount: number; |
|
|
|
|
|
@Column({ nullable: true }) |
|
|
lastUsedAt?: Date; |
|
|
|
|
|
@CreateDateColumn() |
|
|
createdAt: Date; |
|
|
|
|
|
@UpdateDateColumn() |
|
|
updatedAt: Date; |
|
|
} |
|
|
|