diff --git a/ghost/offers/lib/application/OfferRepository.js b/ghost/core/core/server/services/offers/OfferBookshelfRepository.js similarity index 96% rename from ghost/offers/lib/application/OfferRepository.js rename to ghost/core/core/server/services/offers/OfferBookshelfRepository.js index 69ed24e7db..0c104c68f5 100644 --- a/ghost/offers/lib/application/OfferRepository.js +++ b/ghost/core/core/server/services/offers/OfferBookshelfRepository.js @@ -1,7 +1,7 @@ const {flowRight} = require('lodash'); const {mapKeyValues, mapQuery} = require('@tryghost/mongo-utils'); const DomainEvents = require('@tryghost/domain-events'); -const Offer = require('../domain/models/Offer'); +const {Offer} = require('@tryghost/members-offers'); const statusTransformer = mapKeyValues({ key: { @@ -40,7 +40,7 @@ const mongoTransformer = flowRight(statusTransformer, rejectNonStatusTransformer * @prop {string} filter */ -class OfferRepository { +class OfferBookshelfRepository { /** * @param {{forge: (data: object) => import('bookshelf').Model}} OfferModel * @param {{forge: (data: object) => import('bookshelf').Model}} OfferRedemptionModel @@ -177,7 +177,7 @@ class OfferRepository { } /** - * @param {Offer} offer + * @param {import('@tryghost/members-offers').Offer} offer * @param {BaseOptions} [options] * @returns {Promise} */ @@ -219,4 +219,4 @@ class OfferRepository { } } -module.exports = OfferRepository; +module.exports = OfferBookshelfRepository; diff --git a/ghost/core/core/server/services/offers/service.js b/ghost/core/core/server/services/offers/service.js index 7f51761138..0ff7a5746b 100644 --- a/ghost/core/core/server/services/offers/service.js +++ b/ghost/core/core/server/services/offers/service.js @@ -4,6 +4,7 @@ const OffersModule = require('@tryghost/members-offers'); const config = require('../../../shared/config'); const urlUtils = require('../../../shared/url-utils'); const models = require('../../models'); +const OfferBookshelfRepository = require('./OfferBookshelfRepository'); let redirectManager; @@ -15,10 +16,13 @@ module.exports = { return urlUtils.urlJoin(urlUtils.getSubdir(), pathname); } }); + const repository = new OfferBookshelfRepository( + models.Offer, + models.OfferRedemption + ); const offersModule = OffersModule.create({ - OfferModel: models.Offer, - OfferRedemptionModel: models.OfferRedemption, - redirectManager + redirectManager, + repository }); this.api = offersModule.api; diff --git a/ghost/offers/lib/OffersModule.js b/ghost/offers/lib/OffersModule.js index a21cfa51b4..ace06f865f 100644 --- a/ghost/offers/lib/OffersModule.js +++ b/ghost/offers/lib/OffersModule.js @@ -5,14 +5,13 @@ const DomainEvents = require('@tryghost/domain-events'); const OfferCodeChangeEvent = require('./domain/events/OfferCodeChangeEvent'); const OfferCreatedEvent = require('./domain/events/OfferCreatedEvent'); const Offer = require('./domain/models/Offer'); -const OfferRepository = require('./application/OfferRepository'); const OffersAPI = require('./application/OffersAPI'); class OffersModule { /** * @param {OffersAPI} offersAPI * @param {import('@tryghost/express-dynamic-redirects')} redirectManager - * @param {OfferRepository} repository + * @param {any} repository */ constructor(offersAPI, redirectManager, repository) { this.api = offersAPI; @@ -57,15 +56,13 @@ class OffersModule { /** * @param {object} deps * @param {import('@tryghost/express-dynamic-redirects')} deps.redirectManager - * @param {any} deps.OfferModel - * @param {any} deps.OfferRedemptionModel + * @param {any} deps.repository * * @returns {OffersModule} */ static create(deps) { - const repository = new OfferRepository(deps.OfferModel, deps.OfferRedemptionModel); - const offersAPI = new OffersAPI(repository); - return new OffersModule(offersAPI, deps.redirectManager, repository); + const offersAPI = new OffersAPI(deps.repository); + return new OffersModule(offersAPI, deps.redirectManager, deps.repository); } static events = { @@ -73,8 +70,6 @@ class OffersModule { OfferCodeChangeEvent }; - static OfferRepository = OfferRepository; - static Offer = Offer; static OffersAPI = OffersAPI;