diff --git a/ghost/core/core/server/services/collections/index.js b/ghost/core/core/server/services/collections/index.js index f6e787630e..102ef66d4f 100644 --- a/ghost/core/core/server/services/collections/index.js +++ b/ghost/core/core/server/services/collections/index.js @@ -1,58 +1 @@ -const { - CollectionsService, - CollectionsRepositoryInMemory -} = require('@tryghost/collections'); -const labs = require('../../../shared/labs'); - -class CollectionsServiceWrapper { - /** @type {CollectionsService} */ - api; - - constructor() { - const postsRepository = require('./PostsRepository').getInstance(); - const collectionsRepositoryInMemory = new CollectionsRepositoryInMemory(); - const DomainEvents = require('@tryghost/domain-events'); - - const collectionsService = new CollectionsService({ - collectionsRepository: collectionsRepositoryInMemory, - postsRepository: postsRepository, - DomainEvents: DomainEvents - }); - - this.api = collectionsService; - } - - async init() { - if (!labs.isSet('collections')) { - return; - } - - const translateModelEventsToDomainEvents = require('./model-to-domain-events-bridge'); - const existingBuiltins = await this.api.getAll({filter: 'slug:featured'}); - - if (!existingBuiltins.data.length) { - await this.api.createCollection({ - title: 'Index', - slug: 'index', - description: 'Collection with all posts', - type: 'automatic', - deletable: false, - filter: 'status:published' - }); - - await this.api.createCollection({ - title: 'Featured Posts', - slug: 'featured', - description: 'Collection of featured posts', - type: 'automatic', - deletable: false, - filter: 'featured:true' - }); - } - - this.api.subscribeToEvents(); - translateModelEventsToDomainEvents(); - } -} - -module.exports = new CollectionsServiceWrapper(); +module.exports = require('./service'); diff --git a/ghost/core/core/server/services/collections/service.js b/ghost/core/core/server/services/collections/service.js new file mode 100644 index 0000000000..f6e787630e --- /dev/null +++ b/ghost/core/core/server/services/collections/service.js @@ -0,0 +1,58 @@ +const { + CollectionsService, + CollectionsRepositoryInMemory +} = require('@tryghost/collections'); +const labs = require('../../../shared/labs'); + +class CollectionsServiceWrapper { + /** @type {CollectionsService} */ + api; + + constructor() { + const postsRepository = require('./PostsRepository').getInstance(); + const collectionsRepositoryInMemory = new CollectionsRepositoryInMemory(); + const DomainEvents = require('@tryghost/domain-events'); + + const collectionsService = new CollectionsService({ + collectionsRepository: collectionsRepositoryInMemory, + postsRepository: postsRepository, + DomainEvents: DomainEvents + }); + + this.api = collectionsService; + } + + async init() { + if (!labs.isSet('collections')) { + return; + } + + const translateModelEventsToDomainEvents = require('./model-to-domain-events-bridge'); + const existingBuiltins = await this.api.getAll({filter: 'slug:featured'}); + + if (!existingBuiltins.data.length) { + await this.api.createCollection({ + title: 'Index', + slug: 'index', + description: 'Collection with all posts', + type: 'automatic', + deletable: false, + filter: 'status:published' + }); + + await this.api.createCollection({ + title: 'Featured Posts', + slug: 'featured', + description: 'Collection of featured posts', + type: 'automatic', + deletable: false, + filter: 'featured:true' + }); + } + + this.api.subscribeToEvents(); + translateModelEventsToDomainEvents(); + } +} + +module.exports = new CollectionsServiceWrapper();