Search…
Trigger
1
class Triggered {
2
3
@trigger('create.before', 'create.after', {
4
name: 'c_object_with_prop',
5
active: true,
6
principal: 'c_ok',
7
environment: 'production',
8
weight: 0.7
9
})
10
check({ memo, context, old, new, dryRun, inline, event, runtime }) {
11
12
console.log('checking')
13
14
}
15
16
static bakeMeACake() {
17
18
return true
19
20
}
21
22
}
Copied!

@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

1
const { object, trigger, log } = require('decorators')
2
3
@object('c_ctxapi_340_trigger_object')
4
class TriggerObject extends CortexObject {
5
6
@trigger('create.before', { name: 'c_before_create_trigger', object: 'c_ctxapi_340_trigger_object', weight: 1 })
7
beforeCreate({ context }) {
8
context.update('c_before', new Date().getTime())
9
}
10
11
@trigger('create.after', { object: 'c_ctxapi_340_trigger_object', weight: 1 })
12
afterCreate({ context }) {
13
org.objects[context.object].updateOne({ _id: context._id }, {
14
$set: {
15
c_after: new Date().getTime()
16
}
17
}).execute()
18
}
19
20
}
21
22
// Override create.before trigger
23
@object('c_ctxapi_340_trigger_object')
24
class MyCustomTrigger {
25
@trigger('create.before', { name: 'c_before_create_trigger', object: 'c_ctxapi_340_trigger_object', weight: 2 })
26
beforeCreate({ context }) {
27
context.update('c_before', 'overwritten data')
28
}
29
}
Copied!