mirror of
https://github.com/movie-web/backend.git
synced 2025-09-13 18:13:26 +00:00
session management
This commit is contained in:
46
src/db/models/Session.ts
Normal file
46
src/db/models/Session.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Entity, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { randomUUID } from 'crypto';
|
||||
|
||||
@Entity({ tableName: 'sessions' })
|
||||
export class Session {
|
||||
@PrimaryKey({ name: 'id', type: 'uuid' })
|
||||
id: string = randomUUID();
|
||||
|
||||
@Property({ name: 'user', type: 'uuid' })
|
||||
user!: string;
|
||||
|
||||
@Property({ type: 'date' })
|
||||
createdAt: Date = new Date();
|
||||
|
||||
@Property({ type: 'date' })
|
||||
accessedAt!: Date;
|
||||
|
||||
@Property({ type: 'date' })
|
||||
expiresAt!: Date;
|
||||
|
||||
@Property({ type: 'text' })
|
||||
device!: string;
|
||||
|
||||
@Property({ type: 'text' })
|
||||
userAgent!: string;
|
||||
}
|
||||
|
||||
export interface SessionDTO {
|
||||
id: string;
|
||||
user: string;
|
||||
createdAt: string;
|
||||
accessedAt: string;
|
||||
device: string;
|
||||
userAgent: string;
|
||||
}
|
||||
|
||||
export function formatSession(session: Session): SessionDTO {
|
||||
return {
|
||||
id: session.id,
|
||||
user: session.id,
|
||||
createdAt: session.createdAt.toISOString(),
|
||||
accessedAt: session.accessedAt.toISOString(),
|
||||
device: session.device,
|
||||
userAgent: session.userAgent,
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user