Ghost/ghost/offers/lib/domain/models/OfferCadence.js
Fabien O'Carroll 35f150bcf4 Moved errors to domain/errors
no-issue

More cleanup to pull files into their appropriate responsibility
2021-10-08 12:31:11 +02:00

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;