Ghost/ghost/offers/lib/domain/models/OfferDuration.js
Fabien O'Carroll 6d383c2d0e Added support for "once" and "forever" Offer duration
refs https://github.com/TryGhost/Team/issues/1083

Instead of Offers being hardcoded to the "once" duration this will allow
Admins to start creating offers of variable durations.
2021-10-07 17:13:23 +02:00

26 lines
833 B
JavaScript

const ValueObject = require('../../shared/ValueObject');
const InvalidOfferDuration = require('../../errors').InvalidOfferDuration;
/**
* @extends ValueObject<'once'|'repeating'|'forever'>
*/
class OfferDuration extends ValueObject {
/** @param {unknown} duration */
static create(duration) {
if (!duration || typeof duration !== 'string') {
throw new InvalidOfferDuration({
message: 'Offer `duration` must be a string.'
});
}
if (duration !== 'once' && duration !== 'repeating' && duration !== 'forever') {
throw new InvalidOfferDuration({
message: 'Offer `duration` must be one of "once", "repeating" or "forever".'
});
}
return new OfferDuration(duration);
}
}
module.exports = OfferDuration;