diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2024-03-15 20:23:41 +0000 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2024-03-15 20:23:41 +0000 |
| commit | aeb8b66375335e8c9d6cb9cb0d8d7da3d8b79628 (patch) | |
| tree | 0ddaa24fc536ac03493d6357e481df31dad77b16 /src/file/entity | |
Initial commit
Diffstat (limited to 'src/file/entity')
| -rw-r--r-- | src/file/entity/file.entity.ts | 47 | ||||
| -rw-r--r-- | src/file/entity/purpose.entity.ts | 10 |
2 files changed, 57 insertions, 0 deletions
diff --git a/src/file/entity/file.entity.ts b/src/file/entity/file.entity.ts new file mode 100644 index 0000000..49c0ecc --- /dev/null +++ b/src/file/entity/file.entity.ts @@ -0,0 +1,47 @@ +import { nanoid } from 'nanoid'; +import { Session } from '../../session/entity/session.entity'; +import { + Entity, + Column, + BeforeInsert, + CreateDateColumn, + PrimaryGeneratedColumn, + ManyToOne, + Index, + OneToOne, +} from 'typeorm'; +import { FilePurpose } from './purpose.entity'; +import { StoredFile } from 'src/storage/entity/stored-file.entity'; + +@Entity() +export class FileMetadata { + @PrimaryGeneratedColumn() + id: number; + + @Index('filekey-idx') + @Column({ unique: true, nullable: false }) + key: string; + + @ManyToOne(() => FilePurpose, { nullable: false }) + purpose: FilePurpose; + + @CreateDateColumn() + creationDate: Date; + + @Column() + validUntil: Date; + + @Column({ default: false }) + used: boolean; + + @ManyToOne(() => Session, (session) => session.files, { nullable: false }) + session: Session; + + @OneToOne(() => StoredFile, (file) => file.fileMetadata, { nullable: true }) + contents: StoredFile; + + @BeforeInsert() + private beforeInsert() { + this.key = nanoid(); + } +} diff --git a/src/file/entity/purpose.entity.ts b/src/file/entity/purpose.entity.ts new file mode 100644 index 0000000..27c3ad6 --- /dev/null +++ b/src/file/entity/purpose.entity.ts @@ -0,0 +1,10 @@ +import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; + +@Entity() +export class FilePurpose { + @PrimaryGeneratedColumn() + id: number; + + @Column({ nullable: false }) + name: string; +} |
