summaryrefslogtreecommitdiff
path: root/src/models/entities/gallery-post.ts
blob: f59cd671f36f5540df72053752f0d007c7125dfa (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Entity, Index, JoinColumn, Column, PrimaryColumn, ManyToOne } from 'typeorm';
import { User } from './user';
import { id } from '../id';
import { DriveFile } from './drive-file';

@Entity()
export class GalleryPost {
	@PrimaryColumn(id())
	public id: string;

	@Index()
	@Column('timestamp with time zone', {
		comment: 'The created date of the GalleryPost.'
	})
	public createdAt: Date;

	@Index()
	@Column('timestamp with time zone', {
		comment: 'The updated date of the GalleryPost.'
	})
	public updatedAt: Date;

	@Column('varchar', {
		length: 256,
	})
	public title: string;

	@Column('varchar', {
		length: 2048, nullable: true
	})
	public description: string | null;

	@Index()
	@Column({
		...id(),
		comment: 'The ID of author.'
	})
	public userId: User['id'];

	@ManyToOne(type => User, {
		onDelete: 'CASCADE'
	})
	@JoinColumn()
	public user: User | null;

	@Index()
	@Column({
		...id(),
		array: true, default: '{}'
	})
	public fileIds: DriveFile['id'][];

	@Index()
	@Column('boolean', {
		default: false,
		comment: 'Whether the post is sensitive.'
	})
	public isSensitive: boolean;

	@Index()
	@Column('integer', {
		default: 0
	})
	public likedCount: number;

	@Index()
	@Column('varchar', {
		length: 128, array: true, default: '{}'
	})
	public tags: string[];

	constructor(data: Partial<GalleryPost>) {
		if (data == null) return;

		for (const [k, v] of Object.entries(data)) {
			(this as any)[k] = v;
		}
	}
}