How to use the @node-ts/bus-workflow.StartedBy function in @node-ts/bus-workflow

To help you get started, we’ve selected a few @node-ts/bus-workflow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-ts / bus-starter / src / workflows / siren-test-workflow.ts View on Github external
import { Workflow, StartedBy, Handles } from '@node-ts/bus-workflow'
import { SirenTestWorkflowData } from './sirent-test-workflow-data'
import { SirenTestStarted, SirenTestFailed, SirenTestPassed, EmailMaintenanceTeam, MaintenanceTeamEmailed } from '../messages'
import { inject } from 'inversify'
import { BUS_SYMBOLS, Bus } from '@node-ts/bus-core'

export class SirenTestWorkflow extends Workflow {

  constructor (
    @inject(BUS_SYMBOLS.Bus) private readonly bus: Bus
  ) {
    super()
  }

  @StartedBy(SirenTestStarted)
  handlesSirenTestStarted ({ sirenId }: SirenTestStarted): Partial {
    return {
      sirenId
    }
  }

  @Handles(
    SirenTestFailed,
    event => event.sirenId,
    'sirenId'
  )
  async handlesSirenTestFailed ({ sirenId }: SirenTestFailed): Promise> {
    const emailMaintenanceTeam = new EmailMaintenanceTeam(
      'A siren has failed its test and requires maintenance',
      sirenId
    )