Ghost/ghost/offers/lib/domain/models/OfferStatus.js
Hannah Wolfe 3dcf85d5e4 Ensured correct usage of @tryghost/errors everywhere
refs: 23b383bedf

- @tryghost/error constructors take an object, not a string - the expectation is that message, context & help should all be set
- This does the bare minimum and just ensures message is set correctly
2022-02-15 12:30:36 +00:00

26 lines
788 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);
}
static InvalidOfferStatus = InvalidOfferStatus;
}
module.exports = OfferStatus;