template-saas-backend-v2/src/modules/auth/entities/oauth-connection.entity.ts
rckrdmrd dfe6a715f0 Initial commit - Backend de template-saas migrado desde monorepo
Migración desde workspace-v2/projects/template-saas/apps/backend
Este repositorio es parte del estándar multi-repo v2

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 08:07:11 -06:00

77 lines
1.8 KiB
TypeScript

import {
Entity,
Column,
PrimaryGeneratedColumn,
CreateDateColumn,
UpdateDateColumn,
Index,
ManyToOne,
JoinColumn,
} from 'typeorm';
import { User } from './user.entity';
import { OAuthProvider } from './oauth-provider.enum';
@Entity({ schema: 'auth', name: 'oauth_connections' })
@Index(['tenant_id', 'user_id'])
@Index(['tenant_id', 'provider', 'provider_user_id'], { unique: true })
export class OAuthConnection {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ type: 'uuid' })
@Index()
tenant_id: string;
@Column({ type: 'uuid' })
@Index()
user_id: string;
@Column({
type: 'enum',
enum: OAuthProvider,
enumName: 'auth.oauth_provider',
})
provider: OAuthProvider;
@Column({ type: 'varchar', length: 255 })
provider_user_id: string;
@Column({ type: 'varchar', length: 255, nullable: true })
provider_email: string | null;
@Column({ type: 'varchar', length: 255, nullable: true })
provider_name: string | null;
@Column({ type: 'varchar', length: 500, nullable: true })
provider_avatar_url: string | null;
@Column({ type: 'text', nullable: true })
access_token: string | null;
@Column({ type: 'text', nullable: true })
refresh_token: string | null;
@Column({ type: 'timestamp with time zone', nullable: true })
token_expires_at: Date | null;
@Column({ type: 'jsonb', nullable: true })
scopes: string[] | null;
@Column({ type: 'jsonb', nullable: true })
raw_data: Record<string, any> | null;
@CreateDateColumn({ type: 'timestamp with time zone' })
created_at: Date;
@UpdateDateColumn({ type: 'timestamp with time zone' })
updated_at: Date;
@Column({ type: 'timestamp with time zone', nullable: true })
last_used_at: Date | null;
// Relations
@ManyToOne(() => User, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'user_id' })
user: User;
}