Trigger

class Triggered {

  @trigger('create.before', 'create.after',  {
    name: 'c_object_with_prop',
    active: true,
    principal: 'c_ok',
    environment: 'production',
    weight: 0.7
  })
  check({ memo, context, old, new, dryRun, inline, event, runtime }) {

    console.log('checking')

  }

  static bakeMeACake() {

      return true

  }

}

@trigger(...events, options)

Arguments

  • events { String[] } Event list

  • options { Object } Options object

    • name { String }

    • type { String }

    • principal { String }

    • environment { String = "*" }

    • weight { Number = 0 }

    • object { String }

    • event { String }

    • inline { Boolean }

    • paths { String[] }

Method Options

  • methodOptions { Object } Options passed to the method

    • memo { Object }

    • context { Object }

    • old { Object }

    • new { Object }

    • modified { String[] }

    • dryRun { Boolean }

    • inline { Boolean }

    • event { String }

    • runtime { Object }

      • name { String }

      • type { String }

      • principal { String }

      • environment { String = "*" }

      • weight { Number = 0 }

      • configuration { Object }

        • object { String }

        • event { String }

        • inline { Boolean }

        • paths { String[] }

      • metadata { Object }

        • resource { String }

        • className { String }

        • methodName { String }

        • static { Boolean }

        • loc { Object }

          • line { String }

          • column { String }

Examples

const { object, trigger, log } = require('decorators')

@object('c_ctxapi_340_trigger_object')
class TriggerObject extends CortexObject {

  @trigger('create.before', { name: 'c_before_create_trigger', object: 'c_ctxapi_340_trigger_object', weight: 1 })
  beforeCreate({ context }) {
    context.update('c_before', new Date().getTime())
  }

  @trigger('create.after', { object: 'c_ctxapi_340_trigger_object', weight: 1 })
  afterCreate({ context }) {
    org.objects[context.object].updateOne({ _id: context._id }, {
      $set: {
        c_after: new Date().getTime()
      }
    }).execute()
  }

}

// Override create.before trigger
@object('c_ctxapi_340_trigger_object')
class MyCustomTrigger {
  @trigger('create.before', { name: 'c_before_create_trigger', object: 'c_ctxapi_340_trigger_object', weight: 2 })
  beforeCreate({ context }) {
    context.update('c_before', 'overwritten data')
  }
}

Last updated