Spaces:
Runtime error
Runtime error
| import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Unique } from 'typeorm'; | |
| import { DateTransformer } from '../../../common/transformers/date.transformer'; | |
| import { jsonColumnType, dateColumnType } from '../../../common/utils/column-types'; | |
| export enum BatchStatus { | |
| PENDING = 'pending', | |
| PROCESSING = 'processing', | |
| COMPLETED = 'completed', | |
| CANCELLED = 'cancelled', | |
| FAILED = 'failed', | |
| } | |
| export enum BatchMessageStatus { | |
| PENDING = 'pending', | |
| SENT = 'sent', | |
| FAILED = 'failed', | |
| CANCELLED = 'cancelled', | |
| } | |
| export interface BatchMessageResult { | |
| chatId: string; | |
| status: BatchMessageStatus; | |
| messageId?: string; | |
| error?: { | |
| code: string; | |
| message: string; | |
| }; | |
| sentAt?: Date; | |
| } | |
| export interface BatchProgress { | |
| total: number; | |
| sent: number; | |
| failed: number; | |
| pending: number; | |
| cancelled: number; | |
| } | |
| ('message_batches') | |
| // Uniqueness is scoped to the session, not global: one session can't deny a batch id to another. | |
| // Migration 1781800000000 carries the same constraint on existing databases. | |
| ('UQ_message_batches_session_id_batch_id', ['sessionId', 'batchId']) | |
| export class MessageBatch { | |
| ('uuid') | |
| id: string; | |
| ({ name: 'batch_id' }) | |
| batchId: string; | |
| ({ name: 'session_id' }) | |
| sessionId: string; | |
| ({ type: 'varchar', default: BatchStatus.PENDING }) | |
| status: BatchStatus; | |
| ({ type: jsonColumnType() }) | |
| messages: Array<{ | |
| chatId: string; | |
| type: string; | |
| content: Record<string, unknown>; | |
| variables?: Record<string, string>; | |
| }>; | |
| ({ type: jsonColumnType(), nullable: true }) | |
| options: { | |
| delayBetweenMessages: number; | |
| randomizeDelay: boolean; | |
| stopOnError: boolean; | |
| }; | |
| ({ type: jsonColumnType(), nullable: true }) | |
| progress: BatchProgress; | |
| ({ type: jsonColumnType(), nullable: true }) | |
| results: BatchMessageResult[]; | |
| ({ name: 'current_index', default: 0 }) | |
| currentIndex: number; | |
| ({ name: 'created_at' }) | |
| createdAt: Date; | |
| ({ name: 'updated_at' }) | |
| updatedAt: Date; | |
| ({ name: 'started_at', type: dateColumnType(), nullable: true, transformer: DateTransformer }) | |
| startedAt: Date | null; | |
| ({ name: 'completed_at', type: dateColumnType(), nullable: true, transformer: DateTransformer }) | |
| completedAt: Date | null; | |
| } | |