mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
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.
This commit is contained in:
parent
d0bea0d607
commit
9771e1f5c1
2 changed files with 59 additions and 58 deletions
|
@ -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');
|
||||
|
|
58
ghost/core/core/server/services/collections/service.js
Normal file
58
ghost/core/core/server/services/collections/service.js
Normal file
|
@ -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();
|
Loading…
Reference in a new issue