Spaces:
Sleeping
Sleeping
File size: 1,086 Bytes
a38b26a 9f03bd9 a38b26a fcab6da a38b26a 3d80391 a38b26a 9f03bd9 a38b26a 9f03bd9 a38b26a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
ManyToOne,
JoinColumn,
} from 'typeorm';
import type { Relation } from 'typeorm';
import type { User } from './user.entity';
@Entity('sessions')
export class Session {
@PrimaryGeneratedColumn({ name: 'session_id' })
sessionId: number;
@Column({ name: 'user_id', type: 'bigint', unsigned: true })
userId: number;
@Column({ name: 'session_token', type: 'text' })
sessionToken: string;
@Column({ name: 'ip_address', length: 45, nullable: true })
ipAddress?: string;
@Column({ name: 'user_agent', type: 'text', nullable: true })
userAgent?: string;
@Column({ name: 'device_type', length: 50, nullable: true })
deviceType?: string;
@Column({ name: 'expires_at', type: 'datetime' })
expiresAt: Date;
@Column({ name: 'remember_me', default: false })
rememberMe: boolean;
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;
// Relationships
@ManyToOne('User', 'sessions', { onDelete: 'CASCADE' })
@JoinColumn({ name: 'user_id' })
user: Relation<User>;
}
|