hippofish/packages/backend/src/models/entities/Page.ts

122 lines
2.2 KiB
TypeScript
Raw Normal View History

import { Entity, Index, JoinColumn, Column, PrimaryColumn, ManyToOne } from 'typeorm';
import { id } from '../id.js';
2022-09-17 20:27:08 +02:00
import { User } from './User.js';
import { DriveFile } from './DriveFile.js';
@Entity()
@Index(['userId', 'name'], { unique: true })
export class Page {
@PrimaryColumn(id())
public id: string;
@Index()
@Column('timestamp with time zone', {
2021-12-09 15:58:30 +01:00
comment: 'The created date of the Page.',
})
public createdAt: Date;
@Index()
@Column('timestamp with time zone', {
2021-12-09 15:58:30 +01:00
comment: 'The updated date of the Page.',
})
public updatedAt: Date;
@Column('varchar', {
length: 256,
})
public title: string;
@Index()
@Column('varchar', {
length: 256,
})
public name: string;
@Column('varchar', {
2021-12-09 15:58:30 +01:00
length: 256, nullable: true,
})
public summary: string | null;
@Column('boolean')
public alignCenter: boolean;
@Column('boolean', {
2021-12-09 15:58:30 +01:00
default: false,
})
public hideTitleWhenPinned: boolean;
@Column('varchar', {
length: 32,
})
public font: string;
@Index()
@Column({
...id(),
2021-12-09 15:58:30 +01:00
comment: 'The ID of author.',
})
public userId: User['id'];
@ManyToOne(type => User, {
2021-12-09 15:58:30 +01:00
onDelete: 'CASCADE',
})
@JoinColumn()
public user: User | null;
@Column({
...id(),
nullable: true,
})
public eyeCatchingImageId: DriveFile['id'] | null;
@ManyToOne(type => DriveFile, {
2021-12-09 15:58:30 +01:00
onDelete: 'CASCADE',
})
@JoinColumn()
public eyeCatchingImage: DriveFile | null;
@Column('jsonb', {
2021-12-09 15:58:30 +01:00
default: [],
})
public content: Record<string, any>[];
@Column('jsonb', {
2021-12-09 15:58:30 +01:00
default: [],
})
public variables: Record<string, any>[];
2020-04-12 20:23:23 +02:00
@Column('varchar', {
length: 16384,
2021-12-09 15:58:30 +01:00
default: '',
2020-04-12 20:23:23 +02:00
})
public script: string;
/**
* public ...
* followers ...
* specified ... visibleUserIds
*/
@Column('enum', { enum: ['public', 'followers', 'specified'] })
public visibility: 'public' | 'followers' | 'specified';
@Index()
@Column({
...id(),
2021-12-09 15:58:30 +01:00
array: true, default: '{}',
})
public visibleUserIds: User['id'][];
@Column('integer', {
2021-12-09 15:58:30 +01:00
default: 0,
})
public likedCount: number;
constructor(data: Partial<Page>) {
if (data == null) return;
for (const [k, v] of Object.entries(data)) {
(this as any)[k] = v;
}
}
}