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.
This commit is contained in:
Fabien O'Carroll 2021-10-08 12:40:57 +02:00
parent 35f150bcf4
commit 08d3e6e99c

View File

@ -5,7 +5,11 @@ const InvalidOfferDescription = require('../errors').InvalidOfferDescription;
class OfferDescription extends ValueObject {
/** @param {unknown} description */
static create(description) {
if (!description || typeof description !== 'string') {
if (description === null || description === undefined) {
return new OfferDescription('');
}
if (typeof description !== 'string') {
throw new InvalidOfferDescription({
message: 'Offer `display_description` must be a string.'
});