mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
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;
|
||
|
|