Wired up events to CollectionsBookshelfRepository
refs https://github.com/TryGhost/Arch/issues/95 This handles actually dispatching the events
This commit is contained in:
parent
673b06119b
commit
c6f2c985f1
@ -12,9 +12,12 @@ const {default: ObjectID} = require('bson-objectid');
|
||||
module.exports = class BookshelfCollectionsRepository {
|
||||
#model;
|
||||
#relationModel;
|
||||
constructor(model, relationModel) {
|
||||
/** @type {import('@tryghost/domain-events')} */
|
||||
#DomainEvents;
|
||||
constructor(model, relationModel, DomainEvents) {
|
||||
this.#model = model;
|
||||
this.#relationModel = relationModel;
|
||||
this.#DomainEvents = DomainEvents;
|
||||
}
|
||||
|
||||
async createTransaction(cb) {
|
||||
@ -241,6 +244,12 @@ module.exports = class BookshelfCollectionsRepository {
|
||||
if (collectionPostRelationsToDeleteIds.length > 0) {
|
||||
await this.#relationModel.query().delete().whereIn('id', collectionPostRelationsToDeleteIds).transacting(options.transaction);
|
||||
}
|
||||
|
||||
options.transaction.executionPromise.then(() => {
|
||||
for (const event of collection.events) {
|
||||
this.#DomainEvents.dispatch(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -12,7 +12,7 @@ class CollectionsServiceWrapper {
|
||||
const DomainEvents = require('@tryghost/domain-events');
|
||||
const postsRepository = require('./PostsRepository').getInstance();
|
||||
const models = require('../../models');
|
||||
const collectionsRepositoryInMemory = new BookshelfCollectionsRepository(models.Collection, models.CollectionPost);
|
||||
const collectionsRepositoryInMemory = new BookshelfCollectionsRepository(models.Collection, models.CollectionPost, DomainEvents);
|
||||
|
||||
const collectionsService = new CollectionsService({
|
||||
collectionsRepository: collectionsRepositoryInMemory,
|
||||
|
Loading…
Reference in New Issue
Block a user