Defines a callback to be executed on specific CMS operations CmsTrigger
Example
typescript
const trigger = new CmsTrigger('insert-one', (context) => {
console.log('New CMS document inserted:', context.queryResult);
// Perform additional actions after CMS document insertion.
});
// Use the trigger in RestOptions
const { app } = await createRest({
authTriggers: [trigger],
// ... other options
});Extends
Constructors
Constructor
new CmsTrigger(
operation,callback?):CmsTrigger
Creates a new CmsTrigger instance
Example
typescript
// Log all CMS updates
const updateTrigger = new CmsTrigger('update-one', (context) => {
console.log('CMS document updated:', context.queryResult);
});
// Track CMS document removals
const removeTrigger = new CmsTrigger('remove-one', (context) => {
console.log('CMS document removed:', context.queryResult);
});Parameters
| Parameter | Type | Description |
|---|---|---|
operation | CmsOperation | The CMS operation to trigger on |
callback? | (context) => void | The callback function to execute |
Returns
CmsTrigger
Overrides
DatabaseTrigger.constructor
Properties
| Property | Type | Description | Inherited from |
|---|---|---|---|
callback | (context) => void | The callback function to be executed | DatabaseTrigger.callback |
operation | DatabaseOperation | The CMS operation that triggers the callback | DatabaseTrigger.operation |
Methods
applyToSchema()
applyToSchema(
schema):void
Applies the trigger to a Mongoose schema
Parameters
| Parameter | Type | Description |
|---|---|---|
schema | any | The mongoose schema to apply the trigger to |
Returns
void