mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-11 22:13:20 +03:00
35f150bcf4
no-issue More cleanup to pull files into their appropriate responsibility
25 lines
750 B
JavaScript
25 lines
750 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);
|
|
}
|
|
}
|
|
|
|
module.exports = OfferCadence;
|