42 lines
1018 B
TypeScript
Executable File
42 lines
1018 B
TypeScript
Executable File
import {
|
|
Entity,
|
|
ManyToOne,
|
|
Property,
|
|
OptionalProps,
|
|
Index,
|
|
} from '@mikro-orm/core';
|
|
import { User } from "../../user/entities/user.entity";
|
|
import { Admin } from 'src/modules/admin/entities/admin.entity';
|
|
import { AttachmentType } from '../interfaces/chat';
|
|
import { BaseEntity } from 'src/common/entities/base.entity';
|
|
|
|
@Entity()
|
|
@Index({ properties: ['user'] })
|
|
export class Chat extends BaseEntity {
|
|
[OptionalProps]?: 'createdAt' | 'deletedAt'
|
|
|
|
@Property({ type: 'text' })
|
|
content: string;
|
|
|
|
@ManyToOne(() => User, { nullable: true })
|
|
user?: User | null;
|
|
|
|
@ManyToOne(() => Admin, { nullable: true })
|
|
admin?: Admin | null;
|
|
|
|
@Property({ type: 'json', nullable: true })
|
|
attachments?: AttachmentType[]
|
|
|
|
@Property({ type: 'string' })
|
|
refId!: string
|
|
|
|
@ManyToOne(() => Chat, { nullable: true })
|
|
parent?: Chat
|
|
|
|
@Property({ defaultRaw: 'now()', columnType: 'timestamptz' })
|
|
createdAt: Date = new Date();
|
|
|
|
@Property({ nullable: true, columnType: 'timestamptz' })
|
|
readAt?: Date;
|
|
}
|