live blog implemented

This commit is contained in:
dimitar committed 2026-01-29 04:01:55 +01:00
1 parent e8893c1aae
commit 0351726eeb
36 files changed
+7759 -253

No files matched your search

+96 -1
View File
@@ -7,6 +7,7 @@ import {
ManyToOne,
JoinColumn,
ValueTransformer,
OneToMany,
} from 'typeorm';
class ArrayTransformer implements ValueTransformer {
@@ -15,7 +16,7 @@ class ArrayTransformer implements ValueTransformer {
}
from(value: string): string[] {
try {
return value ? JSON.parse(value) : [];
return value ? (JSON.parse(value) as string[]) : [];
} catch {
return [];
}
@@ -28,6 +29,13 @@ export enum ArticleStatus {
ARCHIVED = 'archived',
}
export enum LiveBlogStatus {
DRAFT = 'draft',
LIVE = 'live',
ENDED = 'ended',
ARCHIVED = 'archived',
}
@Entity('authors')
export class Author {
@PrimaryGeneratedColumn('uuid')
@@ -145,3 +153,90 @@ export class Article {
@JoinColumn({ name: 'categoryId' })
category: Category;
}
@Entity('live_blogs')
export class LiveBlog {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column()
title: string;
@Column({ unique: true })
slug: string;
@Column({ type: 'text', nullable: true })
description: string;
@Column({
type: 'text',
default: 'draft',
})
status: LiveBlogStatus;
@Column({ nullable: true })
strapiId: string;
@Column({ nullable: true })
authorId: string;
@Column({ nullable: true })
categoryId: string;
@Column({ default: 0 })
viewCount: number;
@CreateDateColumn()
createdAt: Date;
@UpdateDateColumn()
updatedAt: Date;
@ManyToOne(() => Author, { onDelete: 'SET NULL' })
@JoinColumn({ name: 'authorId' })
author: Author;
@ManyToOne(() => Category, { onDelete: 'SET NULL' })
@JoinColumn({ name: 'categoryId' })
category: Category;
@OneToMany(() => LiveBlogUpdate, (update) => update.liveBlog, {
cascade: true,
})
updates: LiveBlogUpdate[];
}
@Entity('live_blog_updates')
export class LiveBlogUpdate {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column('text')
content: string;
@Column({ default: false })
isPinned: boolean;
@Column({ nullable: true })
authorId: string;
@Column({ type: 'datetime', nullable: true })
scheduledAt: Date;
@Column({ nullable: true })
strapiId: string;
@CreateDateColumn()
createdAt: Date;
@UpdateDateColumn()
updatedAt: Date;
@ManyToOne(() => Author, { onDelete: 'SET NULL' })
@JoinColumn({ name: 'authorId' })
author: Author;
@ManyToOne(() => LiveBlog, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'liveBlogId' })
liveBlog: LiveBlog;
}