Added bulk posts action events dispatching
refs https://github.com/TryGhost/Arch/issues/16 - Allows to subscribe to bulk unpublish/featured/unfeatured DomainEvents elsewhere in the system, for example, Collections.
This commit is contained in:
parent
f4143a8939
commit
18a4fa8cd9
13
ghost/post-events/src/PostsBulkFeaturedEvent.ts
Normal file
13
ghost/post-events/src/PostsBulkFeaturedEvent.ts
Normal file
@ -0,0 +1,13 @@
|
||||
export class PostsBulkFeaturedEvent {
|
||||
data: string[];
|
||||
timestamp: Date;
|
||||
|
||||
constructor(data: string[], timestamp: Date) {
|
||||
this.data = data;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
static create(data: string[], timestamp = new Date()) {
|
||||
return new PostsBulkFeaturedEvent(data, timestamp);
|
||||
}
|
||||
}
|
13
ghost/post-events/src/PostsBulkUnfeaturedEvent.ts
Normal file
13
ghost/post-events/src/PostsBulkUnfeaturedEvent.ts
Normal file
@ -0,0 +1,13 @@
|
||||
export class PostsBulkUnfeaturedEvent {
|
||||
data: string[];
|
||||
timestamp: Date;
|
||||
|
||||
constructor(data: string[], timestamp: Date) {
|
||||
this.data = data;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
static create(data: string[], timestamp = new Date()) {
|
||||
return new PostsBulkUnfeaturedEvent(data, timestamp);
|
||||
}
|
||||
}
|
13
ghost/post-events/src/PostsBulkUnpublishedEvent.ts
Normal file
13
ghost/post-events/src/PostsBulkUnpublishedEvent.ts
Normal file
@ -0,0 +1,13 @@
|
||||
export class PostsBulkUnpublishedEvent {
|
||||
data: string[];
|
||||
timestamp: Date;
|
||||
|
||||
constructor(data: string[], timestamp: Date) {
|
||||
this.data = data;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
static create(data: string[], timestamp = new Date()) {
|
||||
return new PostsBulkUnpublishedEvent(data, timestamp);
|
||||
}
|
||||
}
|
@ -1 +1,4 @@
|
||||
export * from './PostsBulkDestroyedEvent';
|
||||
export * from './PostsBulkUnpublishedEvent';
|
||||
export * from './PostsBulkFeaturedEvent';
|
||||
export * from './PostsBulkUnfeaturedEvent';
|
||||
|
@ -1,5 +1,10 @@
|
||||
import assert from 'assert/strict';
|
||||
import {PostsBulkDestroyedEvent} from '../src/index';
|
||||
import {
|
||||
PostsBulkDestroyedEvent,
|
||||
PostsBulkUnpublishedEvent,
|
||||
PostsBulkFeaturedEvent,
|
||||
PostsBulkUnfeaturedEvent
|
||||
} from '../src/index';
|
||||
|
||||
describe('Post Events', function () {
|
||||
it('Can instantiate BulkDestroyEvent', function () {
|
||||
@ -7,4 +12,22 @@ describe('Post Events', function () {
|
||||
assert.ok(event);
|
||||
assert.equal(event.data.length, 3);
|
||||
});
|
||||
|
||||
it('Can instantiate PostsBulkUnpublishedEvent', function () {
|
||||
const event = PostsBulkUnpublishedEvent.create(['1', '2', '3']);
|
||||
assert.ok(event);
|
||||
assert.equal(event.data.length, 3);
|
||||
});
|
||||
|
||||
it('Can instantiate PostsBulkFeaturedEvent', function () {
|
||||
const event = PostsBulkFeaturedEvent.create(['1', '2', '3']);
|
||||
assert.ok(event);
|
||||
assert.equal(event.data.length, 3);
|
||||
});
|
||||
|
||||
it('Can instantiate PostsBulkUnfeaturedEvent', function () {
|
||||
const event = PostsBulkUnfeaturedEvent.create(['1', '2', '3']);
|
||||
assert.ok(event);
|
||||
assert.equal(event.data.length, 3);
|
||||
});
|
||||
});
|
||||
|
@ -5,7 +5,12 @@ const errors = require('@tryghost/errors');
|
||||
const ObjectId = require('bson-objectid').default;
|
||||
const pick = require('lodash/pick');
|
||||
const DomainEvents = require('@tryghost/domain-events/lib/DomainEvents');
|
||||
const {PostsBulkDestroyedEvent} = require('@tryghost/post-events');
|
||||
const {
|
||||
PostsBulkDestroyedEvent,
|
||||
PostsBulkUnpublishedEvent,
|
||||
PostsBulkFeaturedEvent,
|
||||
PostsBulkUnfeaturedEvent
|
||||
} = require('@tryghost/post-events');
|
||||
|
||||
const messages = {
|
||||
invalidVisibilityFilter: 'Invalid visibility filter.',
|
||||
@ -458,6 +463,23 @@ class PostsService {
|
||||
});
|
||||
}
|
||||
|
||||
if (options.actionName) {
|
||||
let bulkActionEvent;
|
||||
switch (options.actionName) {
|
||||
case 'unpublished':
|
||||
bulkActionEvent = PostsBulkUnpublishedEvent.create(editIds);
|
||||
break;
|
||||
case 'featured':
|
||||
bulkActionEvent = PostsBulkFeaturedEvent.create(editIds);
|
||||
break;
|
||||
case 'unfeatured':
|
||||
bulkActionEvent = PostsBulkUnfeaturedEvent.create(editIds);
|
||||
break;
|
||||
}
|
||||
|
||||
DomainEvents.dispatch(bulkActionEvent);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user