mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
3dcf85d5e4
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
26 lines
788 B
JavaScript
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;
|