2021-10-08 13:23:40 +03:00
|
|
|
const ValueObject = require('./shared/ValueObject');
|
2021-10-08 13:31:11 +03:00
|
|
|
const InvalidOfferName = require('../errors').InvalidOfferName;
|
2021-10-07 17:42:56 +03:00
|
|
|
|
|
|
|
/** @extends ValueObject<string> */
|
|
|
|
class OfferName extends ValueObject {
|
|
|
|
/** @param {unknown} name */
|
|
|
|
static create(name) {
|
|
|
|
if (!name || typeof name !== 'string') {
|
|
|
|
throw new InvalidOfferName({
|
|
|
|
message: 'Offer `name` must be a string.'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-25 13:34:33 +03:00
|
|
|
if (name.length > 40) {
|
2021-10-07 17:42:56 +03:00
|
|
|
throw new InvalidOfferName({
|
2021-11-25 13:34:33 +03:00
|
|
|
message: 'Offer `name` can be a maximum of 40 characters.'
|
2021-10-07 17:42:56 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-04 20:52:20 +03:00
|
|
|
return new OfferName(name.trim());
|
2021-10-07 17:42:56 +03:00
|
|
|
}
|
2021-11-04 20:52:20 +03:00
|
|
|
|
2022-02-15 15:27:22 +03:00
|
|
|
static InvalidOfferName = InvalidOfferName;
|
2021-10-07 17:42:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = OfferName;
|