Ghost/ghost/offers/lib/domain/models/OfferTitle.js
Fabien O'Carroll 35f150bcf4 Moved errors to domain/errors
no-issue

More cleanup to pull files into their appropriate responsibility
2021-10-08 12:31:11 +02:00

25 lines
707 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 || 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);
}
}
module.exports = OfferTitle;