From 9771e1f5c1959a76f8f543a14093a61ea59d02a6 Mon Sep 17 00:00:00 2001 From: "Fabien \"egg\" O'Carroll" Date: Thu, 29 Jun 2023 01:19:44 +0100 Subject: [PATCH] Renamed collections service wrapper to service.js This follows our existing patterns and protects us from th eslint max line rule when wiring up dependencies. The rule is designed to keep logic out of glue code, and this file won't have logic, just lots of deps. --- .../core/server/services/collections/index.js | 59 +------------------ .../server/services/collections/service.js | 58 ++++++++++++++++++ 2 files changed, 59 insertions(+), 58 deletions(-) create mode 100644 ghost/core/core/server/services/collections/service.js 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();