Ghost/ghost/offers/lib/domain/models/OfferDescription.js
Fabien O'Carroll 08d3e6e99c Allowed for OfferDescription to be null/empty
refs https://github.com/TryGhost/Team/issues/1083

OfferDescription is not a required field, so we must not throw when it
is falsy or not present.
2021-10-08 12:40:57 +02:00

29 lines
902 B
JavaScript

const ValueObject = require('./shared/ValueObject');
const InvalidOfferDescription = require('../errors').InvalidOfferDescription;
/** @extends ValueObject<string> */
class OfferDescription extends ValueObject {
/** @param {unknown} description */
static create(description) {
if (description === null || description === undefined) {
return new OfferDescription('');
}
if (typeof description !== 'string') {
throw new InvalidOfferDescription({
message: 'Offer `display_description` must be a string.'
});
}
if (description.length > 191) {
throw new InvalidOfferDescription({
message: 'Offer `display_description` can be a maximum of 191 characters.'
});
}
return new OfferDescription(description);
}
}
module.exports = OfferDescription;