mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 17:32:15 +03:00
27 lines
805 B
JavaScript
27 lines
805 B
JavaScript
const ValueObject = require('./shared/ValueObject');
|
|
const InvalidOfferCadence = require('../errors').InvalidOfferCadence;
|
|
|
|
/**
|
|
* @extends ValueObject<'month'|'year'>
|
|
*/
|
|
class OfferCadence extends ValueObject {
|
|
/** @param {unknown} cadence */
|
|
static create(cadence) {
|
|
if (!cadence || typeof cadence !== 'string') {
|
|
throw new InvalidOfferCadence({
|
|
message: 'Offer `cadence` must be a string.'
|
|
});
|
|
}
|
|
if (cadence !== 'month' && cadence !== 'year') {
|
|
throw new InvalidOfferCadence({
|
|
message: 'Offer `cadence` must be one of "month" or "year".'
|
|
});
|
|
}
|
|
return new OfferCadence(cadence);
|
|
}
|
|
|
|
static InvalidOfferCadence = InvalidOfferCadence;
|
|
}
|
|
|
|
module.exports = OfferCadence;
|