Added subscription changed trigger

Is very useful if some subscription data is updated by API and you want to trigger after that because segments (filters) have changed.
This commit is contained in:
Gernot Pansy 2019-10-10 12:35:57 +02:00
parent ed2655b78e
commit e2a69ef76d
8 changed files with 21 additions and 3 deletions

View file

@ -54,6 +54,7 @@ export default class CUD extends Component {
this.eventOptions = {
[Entity.SUBSCRIPTION]: [
{key: SubscriptionEvent.CREATED, label: eventLabels[Entity.SUBSCRIPTION][SubscriptionEvent.CREATED]},
{key: SubscriptionEvent.UPDATED, label: eventLabels[Entity.SUBSCRIPTION][SubscriptionEvent.UPDATED]},
{key: SubscriptionEvent.LATEST_OPEN, label: eventLabels[Entity.SUBSCRIPTION][SubscriptionEvent.LATEST_OPEN]},
{key: SubscriptionEvent.LATEST_CLICK, label: eventLabels[Entity.SUBSCRIPTION][SubscriptionEvent.LATEST_CLICK]}
],

View file

@ -15,6 +15,7 @@ export function getTriggerTypes(t) {
const eventLabels = {
[Entity.SUBSCRIPTION]: {
[SubscriptionEvent.CREATED]: t('created'),
[SubscriptionEvent.UPDATED]: t('updated'),
[SubscriptionEvent.LATEST_OPEN]: t('latestOpen'),
[SubscriptionEvent.LATEST_CLICK]: t('latestClick')
},

View file

@ -145,6 +145,7 @@
"addList": "Add list",
"type": "Type",
"created": "Created",
"updated": "Updated",
"override": "Override",
"fromName": "\"From\" name",
"fromEmailAddress": "\"From\" email address",

@ -1 +1 @@
Subproject commit 5ea4783f3ec5140ad68637c31e230a410e493170
Subproject commit 7d15f154c933c4789d6c9b288fbdf7437be3d856

View file

@ -195,6 +195,7 @@ async function create(context, entity) {
' `latest_open` timestamp NULL DEFAULT NULL,\n' +
' `latest_click` timestamp NULL DEFAULT NULL,\n' +
' `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n' +
' `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n' +
' PRIMARY KEY (`id`),\n' +
' UNIQUE KEY `hash_email` (`hash_email`),\n' +
' UNIQUE KEY `cid` (`cid`),\n' +
@ -204,7 +205,8 @@ async function create(context, entity) {
' KEY `is_test` (`is_test`),\n' +
' KEY `latest_open` (`latest_open`),\n' +
' KEY `latest_click` (`latest_click`),\n' +
' KEY `created` (`created`)\n' +
' KEY `created` (`created`),\n' +
' KEY `updated` (`updated`)\n' +
') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n');
await shares.rebuildPermissionsTx(tx, { entityTypeId: 'list', entityId: id });

View file

@ -616,6 +616,7 @@ async function _update(tx, listId, groupedFieldsMap, existing, filteredEntity) {
}
if (filteredEntity) {
filteredEntity.updated = new Date();
await tx(getSubscriptionTableName(listId)).where('id', existing.id).update(filteredEntity);
if ('status' in filteredEntity) {

View file

@ -0,0 +1,10 @@
exports.up = (knex, Promise) => (async() => {
const lists = await knex('lists');
for (const list of lists) {
await knex.schema.raw('ALTER TABLE `subscription__' + list.id + '` ADD COLUMN `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER `created`');
await knex.schema.raw('CREATE INDEX updated ON `subscription__' + list.id + '` (`updated`)');
}
})();
exports.down = (knex, Promise) => (async() => {
})();

View file

@ -8,6 +8,7 @@ const Entity = {
const Event = {
[Entity.SUBSCRIPTION]: {
CREATED: 'created',
UPDATED: 'updated',
LATEST_OPEN: 'latest_open',
LATEST_CLICK: 'latest_click'
},
@ -28,6 +29,7 @@ const EntityVals = {
const EventVals = {
[Entity.SUBSCRIPTION]: {
created: 'CREATED',
updated: 'UPDATED',
latest_open: 'LATEST_OPEN',
latest_click: 'LATEST_CLICK'
},
@ -45,4 +47,4 @@ module.exports = {
Event,
EntityVals,
EventVals
};
};