1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/backend/model/sql/enitites/DirectoryEntity.ts
2019-02-15 15:49:05 -05:00

64 lines
1.6 KiB
TypeScript

import {Column, Entity, Index, ManyToOne, OneToMany, PrimaryGeneratedColumn, Unique} from 'typeorm';
import {DirectoryDTO} from '../../../../common/entities/DirectoryDTO';
import {MediaEntity} from './MediaEntity';
import {FileEntity} from './FileEntity';
import {columnCharsetCS} from './EntityUtils';
@Entity()
@Unique(['name', 'path'])
export class DirectoryEntity implements DirectoryDTO {
@Index()
@PrimaryGeneratedColumn({unsigned: true})
id: number;
@Index()
@Column(columnCharsetCS)
name: string;
@Index()
@Column()
path: string;
/**
* last time the directory was modified (from outside, eg.: a new media was added)
*/
@Column('bigint', {
unsigned: true, transformer: {
from: v => parseInt(v, 10),
to: v => v
}
})
public lastModified: number;
/**
* Last time the directory was fully scanned, not only for a few media to create a preview
*/
@Column({
type: 'bigint', nullable: true, unsigned: true, transformer: {
from: v => parseInt(v, 10) || null,
to: v => v
}
})
public lastScanned: number;
isPartial?: boolean;
@Column('smallint', {unsigned: true})
mediaCount: number;
@Index()
@ManyToOne(type => DirectoryEntity, directory => directory.directories, {onDelete: 'CASCADE'})
public parent: DirectoryEntity;
@OneToMany(type => DirectoryEntity, dir => dir.parent)
public directories: DirectoryEntity[];
@OneToMany(type => MediaEntity, media => media.directory)
public media: MediaEntity[];
@OneToMany(type => FileEntity, file => file.directory)
public metaFile: FileEntity[];
}