0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Wired up Offer status to the OfferRepository

refs https://github.com/TryGhost/Team/issues/1131

This allows us to persist and hydrate the Offer status from our
database.
This commit is contained in:
Fabien O'Carroll 2021-10-12 15:29:13 +02:00
parent 1f936357d9
commit a772f5b82f

View file

@ -1,6 +1,7 @@
const DomainEvents = require('@tryghost/domain-events');
const OfferCodeChangeEvent = require('../domain/events/OfferCodeChange');
const Offer = require('../domain/models/Offer');
const OfferStatus = require('../domain/models/OfferStatus');
/**
* @typedef {object} OfferRepositoryOptions
@ -25,6 +26,7 @@ function toDomain(json) {
duration: json.duration,
duration_in_months: json.duration_in_months,
stripe_coupon_id: json.stripe_coupon_id,
status: json.active ? 'active' : 'archived',
tier: {
id: json.product.id,
name: json.product.name
@ -125,7 +127,8 @@ class OfferRepository {
product_id: offer.tier.id,
duration: offer.duration.value.type,
duration_in_months: offer.duration.value.type === 'repeating' ? offer.duration.value.months : null,
currency: offer.currency ? offer.currency.value : null
currency: offer.currency ? offer.currency.value : null,
active: offer.status.equals(OfferStatus.create('active'))
});
if (offer.codeChanged || offer.isNew) {