Ghost/ghost/offers/lib/domain/models/OfferTitle.js
Fabien O'Carroll 78be4b55c9 Moved ValueObject to domain/models/shared
no-issue

This is only ever used in this directory so it makes sense to be
colocated.
2021-10-08 12:23:40 +02:00

25 lines
710 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;