58 lines
1020 B
TypeScript
58 lines
1020 B
TypeScript
import {
|
|
Entity,
|
|
PrimaryGeneratedColumn,
|
|
Column,
|
|
CreateDateColumn,
|
|
ManyToOne,
|
|
JoinColumn,
|
|
} from 'typeorm';
|
|
import { Article } from '../entities';
|
|
|
|
export type SharePlatform =
|
|
| 'facebook'
|
|
| 'twitter'
|
|
| 'whatsapp'
|
|
| 'telegram'
|
|
| 'link';
|
|
|
|
@Entity('share_events')
|
|
export class ShareEvent {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id: string;
|
|
|
|
@Column()
|
|
articleId: string;
|
|
|
|
@Column({ type: 'text' })
|
|
platform: SharePlatform;
|
|
|
|
@Column({ nullable: true })
|
|
userId: string;
|
|
|
|
@Column({ nullable: true })
|
|
userAgent: string;
|
|
|
|
@Column({ nullable: true })
|
|
ipAddress: string;
|
|
|
|
@CreateDateColumn()
|
|
createdAt: Date;
|
|
|
|
@ManyToOne(() => Article, { onDelete: 'CASCADE' })
|
|
@JoinColumn({ name: 'articleId' })
|
|
article: Article;
|
|
}
|
|
|
|
export interface ShareStats {
|
|
articleId: string;
|
|
articleTitle: string;
|
|
facebookShares: number;
|
|
twitterShares: number;
|
|
whatsappShares: number;
|
|
telegramShares: number;
|
|
linkShares: number;
|
|
totalShares: number;
|
|
views: number;
|
|
shareRate: number;
|
|
}
|