Allowed OfferTitle to be empty

refs https://github.com/TryGhost/Team/issues/1163

This allows users to not provide a title for an Offer. We store the lack
of a title as `NULL` in the DB, but we will always provide a string to
the API so that the title can safely be used in HTML.
This commit is contained in:
Fabien O'Carroll 2021-10-22 13:41:09 +02:00
parent d522da5d42
commit b6234d6e96
3 changed files with 8 additions and 5 deletions

View File

@ -168,8 +168,8 @@ class OfferRepository {
id: offer.id,
name: offer.name.value,
code: offer.code.value,
portal_title: offer.displayTitle.value,
portal_description: offer.displayDescription.value,
portal_title: offer.displayTitle.value || null,
portal_description: offer.displayDescription.value || null,
discount_type: offer.type.value === 'fixed' ? 'amount' : 'percent',
discount_amount: offer.amount.value,
interval: offer.cadence.value,

View File

@ -21,7 +21,7 @@ class OfferDescription extends ValueObject {
});
}
return new OfferDescription(description);
return new OfferDescription(description.trim());
}
}

View File

@ -5,7 +5,10 @@ const InvalidOfferTitle = require('../errors').InvalidOfferTitle;
class OfferTitle extends ValueObject {
/** @param {unknown} title */
static create(title) {
if (!title || typeof title !== 'string') {
if (title === null || title === undefined) {
return new OfferTitle('');
}
if (typeof title !== 'string') {
throw new InvalidOfferTitle({
message: 'Offer `display_title` must be a string.'
});
@ -17,7 +20,7 @@ class OfferTitle extends ValueObject {
});
}
return new OfferTitle(title);
return new OfferTitle(title.trim());
}
}