aboutsummaryrefslogtreecommitdiffstats
path: root/src/session/entity/session.entity.ts
blob: a4f13ae628469c6f39991a608b3c2ea69fcc67d9 (plain)
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
import { FileMetadata } from '../../file/entity/file.entity';
import { Entity, Column, BeforeInsert, CreateDateColumn, PrimaryGeneratedColumn, Index, OneToMany } from 'typeorm';
import { nanoid } from 'nanoid';

@Entity()
export class Session {
  @PrimaryGeneratedColumn()
  id: number;

  @Index('sessiontoken-idx')
  @Column({ unique: true })
  token: string;

  @CreateDateColumn()
  creationDate: Date;

  @Column()
  validUntil: Date;

  @Column({ default: false })
  used: boolean;

  @OneToMany(() => FileMetadata, (file) => file.session)
  files: FileMetadata[];

  @BeforeInsert()
  private beforeInsert() {
    this.token = nanoid();
  }
}