/
guselnikov
/
inst
Обзор
Документация
Войти
/
guselnikov
/
inst
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
back/src/database/entities/api-token.entity.ts
50 строк
1 KB
Viktor Guselnikov
new
26 июл 2026, 18:42
26 июл 2026, 18:42
322e1f1
Код
Авторство
О чём код?
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn, } from 'typeorm'; @Entity('api_tokens') @Index('IDX_api_tokens_org', ['organizationId']) @Index('UQ_api_tokens_hash', ['tokenHash'], { unique: true }) export class ApiTokenEntity { @PrimaryGeneratedColumn('uuid') id: string; @Column({ name: 'organization_id', type: 'uuid' }) organizationId: string; @Column({ type: 'varchar', length: 120 }) name: string; @Column({ name: 'token_hash', type: 'varchar', length: 64 }) tokenHash: string; @Column({ type: 'text', array: true, default: '{}' }) scopes: string[]; @Column({ name: 'expires_at', type: 'timestamptz', nullable: true }) expiresAt: Date | null; @Column({ name: 'last_used_at', type: 'timestamptz', nullable: true }) lastUsedAt: Date | null; @CreateDateColumn({ name: 'created_at', type: 'timestamptz' }) createdAt: Date; } export const API_TOKEN_SCOPES = [ 'design:read', 'design:write', 'design:tools', ] as const; export type ApiTokenScope = (typeof API_TOKEN_SCOPES)[number]; export type ApiTokenPayload = { tokenId: string; organizationId: string; scopes: string[]; };