2021-10-08 13:23:40 +03:00
|
|
|
const ValueObject = require('./shared/ValueObject');
|
2021-10-08 13:31:11 +03:00
|
|
|
const InvalidOfferTitle = require('../errors').InvalidOfferTitle;
|
2021-10-07 17:42:56 +03:00
|
|
|
|
|
|
|
/** @extends ValueObject<string> */
|
|
|
|
class OfferTitle extends ValueObject {
|
|
|
|
/** @param {unknown} title */
|
|
|
|
static create(title) {
|
2021-10-22 14:41:09 +03:00
|
|
|
if (title === null || title === undefined) {
|
|
|
|
return new OfferTitle('');
|
|
|
|
}
|
|
|
|
if (typeof title !== 'string') {
|
2021-10-07 17:42:56 +03:00
|
|
|
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.'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-22 14:41:09 +03:00
|
|
|
return new OfferTitle(title.trim());
|
2021-10-07 17:42:56 +03:00
|
|
|
}
|
2021-11-04 20:52:20 +03:00
|
|
|
|
|
|
|
static InvalidOfferTitle = InvalidOfferTitle;
|
2021-10-07 17:42:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = OfferTitle;
|