diff --git a/ghost/post-events/src/PostsBulkFeaturedEvent.ts b/ghost/post-events/src/PostsBulkFeaturedEvent.ts new file mode 100644 index 0000000000..c45404a28d --- /dev/null +++ b/ghost/post-events/src/PostsBulkFeaturedEvent.ts @@ -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); + } +} diff --git a/ghost/post-events/src/PostsBulkUnfeaturedEvent.ts b/ghost/post-events/src/PostsBulkUnfeaturedEvent.ts new file mode 100644 index 0000000000..faa742f4b1 --- /dev/null +++ b/ghost/post-events/src/PostsBulkUnfeaturedEvent.ts @@ -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); + } +} diff --git a/ghost/post-events/src/PostsBulkUnpublishedEvent.ts b/ghost/post-events/src/PostsBulkUnpublishedEvent.ts new file mode 100644 index 0000000000..57e83094ec --- /dev/null +++ b/ghost/post-events/src/PostsBulkUnpublishedEvent.ts @@ -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); + } +} diff --git a/ghost/post-events/src/index.ts b/ghost/post-events/src/index.ts index aa29b39e29..d5b4a3f933 100644 --- a/ghost/post-events/src/index.ts +++ b/ghost/post-events/src/index.ts @@ -1 +1,4 @@ export * from './PostsBulkDestroyedEvent'; +export * from './PostsBulkUnpublishedEvent'; +export * from './PostsBulkFeaturedEvent'; +export * from './PostsBulkUnfeaturedEvent'; diff --git a/ghost/post-events/test/post-events.test.ts b/ghost/post-events/test/post-events.test.ts index 9fa179e5cb..e819ca36c2 100644 --- a/ghost/post-events/test/post-events.test.ts +++ b/ghost/post-events/test/post-events.test.ts @@ -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); + }); }); diff --git a/ghost/posts-service/lib/PostsService.js b/ghost/posts-service/lib/PostsService.js index da49228caf..4ad441a7ec 100644 --- a/ghost/posts-service/lib/PostsService.js +++ b/ghost/posts-service/lib/PostsService.js @@ -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; }