mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 09:22:49 +03:00
1f936357d9
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.
24 lines
735 B
JavaScript
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;
|