2021-10-08 13:23:40 +03:00
|
|
|
const ValueObject = require('./shared/ValueObject');
|
2021-10-08 13:31:11 +03:00
|
|
|
const InvalidOfferDescription = require('../errors').InvalidOfferDescription;
|
2021-10-07 17:42:56 +03:00
|
|
|
|
|
|
|
/** @extends ValueObject<string> */
|
|
|
|
class OfferDescription extends ValueObject {
|
|
|
|
/** @param {unknown} description */
|
|
|
|
static create(description) {
|
2021-10-08 13:40:57 +03:00
|
|
|
if (description === null || description === undefined) {
|
|
|
|
return new OfferDescription('');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof description !== 'string') {
|
2021-10-07 17:42:56 +03:00
|
|
|
throw new InvalidOfferDescription({
|
|
|
|
message: 'Offer `display_description` must be a string.'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (description.length > 191) {
|
|
|
|
throw new InvalidOfferDescription({
|
|
|
|
message: 'Offer `display_description` can be a maximum of 191 characters.'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-22 14:41:09 +03:00
|
|
|
return new OfferDescription(description.trim());
|
2021-10-07 17:42:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = OfferDescription;
|