mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-12 06:25:51 +03:00
6d383c2d0e
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.
26 lines
833 B
JavaScript
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;
|
|
|