67 lines
1.5 KiB
TypeScript
67 lines
1.5 KiB
TypeScript
import {
|
|
Entity,
|
|
PrimaryGeneratedColumn,
|
|
Column,
|
|
CreateDateColumn,
|
|
UpdateDateColumn,
|
|
ManyToOne,
|
|
JoinColumn,
|
|
Index,
|
|
} from 'typeorm';
|
|
import { TgAccount } from './tg-account.entity';
|
|
|
|
export enum ChatType {
|
|
PRIVATE = 'private',
|
|
GROUP = 'group',
|
|
SUPERGROUP = 'supergroup',
|
|
CHANNEL = 'channel',
|
|
SECRET = 'secret',
|
|
}
|
|
|
|
@Entity('tg_chats')
|
|
@Index('IDX_tg_chat_account_identity', ['accountId', 'tgChatId'], { unique: true })
|
|
export class TgChat {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id: string;
|
|
|
|
@Column()
|
|
accountId: string;
|
|
|
|
@ManyToOne(() => TgAccount, (account) => account.chats)
|
|
@JoinColumn({ name: 'accountId' })
|
|
account: TgAccount;
|
|
|
|
@Column({ type: 'bigint' })
|
|
tgChatId: number;
|
|
|
|
@Column({ type: 'varchar', length: 50 })
|
|
type: ChatType;
|
|
|
|
@Column({ length: 500 })
|
|
title: string;
|
|
|
|
@Column({ type: 'text', nullable: true })
|
|
lastMessage: string;
|
|
|
|
@Column({ type: 'bigint', default: 0 })
|
|
lastMessageId: number;
|
|
|
|
@Column({ nullable: true })
|
|
lastMessageDate: Date;
|
|
|
|
@Column({ type: 'int', default: 0 })
|
|
unreadCount: number;
|
|
|
|
@Column({ type: 'text', nullable: true, transformer: { to: (v) => v ? JSON.stringify(v) : null, from: (v) => v ? JSON.parse(v) : null } })
|
|
photo: Record<string, unknown>;
|
|
|
|
@Column({ type: 'text', nullable: true, transformer: { to: (v) => v ? JSON.stringify(v) : null, from: (v) => v ? JSON.parse(v) : null } })
|
|
raw: Record<string, unknown>;
|
|
|
|
@CreateDateColumn()
|
|
createdAt: Date;
|
|
|
|
@UpdateDateColumn()
|
|
updatedAt: Date;
|
|
}
|