Ghost/ghost/offers/lib/domain/models/OfferStatus.js
Fabien O'Carroll 1f936357d9 Added concept of OfferStatus to domain model
refs https://github.com/TryGhost/Team/issues/1131

This allows us to model the behaviour of archived & active offers, as
well as allowing us to set their status on the model.
2021-10-12 15:27:27 +02:00

24 lines
735 B
JavaScript

const ValueObject = require('./shared/ValueObject');
const InvalidOfferStatus = require('../errors').InvalidOfferStatus;
/** @extends ValueObject<'active'|'archived'> */
class OfferStatus extends ValueObject {
/** @param {unknown} status */
static create(status) {
if (typeof status !== 'string') {
throw new InvalidOfferStatus({
message: 'Offer `status` must be a string.'
});
}
if (status !== 'active' && status !== 'archived') {
throw new InvalidOfferStatus({
message: 'Offer `status` must be either "active" or "archived".'
});
}
return new OfferStatus(status);
}
}
module.exports = OfferStatus;