All files / apps/work-orders-service/src/messaging outbox-event.entity.ts

100% Statements 10/10
100% Branches 4/4
100% Functions 0/0
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 379x                               9x   9x       9x     9x     9x     9x     9x    
import {
  Column,
  CreateDateColumn,
  Entity,
  Index,
  PrimaryGeneratedColumn,
} from 'typeorm';
import type { WorkOrderEvent } from '@app/contracts';
 
/**
 * Staged domain events, written in the same transaction as the state change
 * they describe. The relay publishes and stamps published_at; a row with a
 * null published_at is the queue. This closes the dual-write gap: either the
 * work order AND its event commit, or neither does.
 */
@Entity('outbox_events')
export class OutboxEvent {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id!: string;
 
  @Index({ unique: true })
  @Column({ name: 'event_id', type: 'uuid' })
  eventId!: string;
 
  @Column({ length: 50 })
  type!: string;
 
  @Column({ type: 'jsonb' })
  payload!: WorkOrderEvent;
 
  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
  createdAt!: Date;
 
  @Column({ name: 'published_at', type: 'timestamptz', nullable: true })
  publishedAt!: Date | null;
}