Ghost/ghost/offers/lib/domain/models/OfferTitle.js
Fabien O'Carroll b6234d6e96 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.
2021-10-22 13:41:09 +02:00

28 lines
806 B
JavaScript

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