Ghost/ghost/offers/lib/domain/models/OfferName.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
676 B
JavaScript

const ValueObject = require('./shared/ValueObject');
const InvalidOfferName = require('../errors').InvalidOfferName;
/** @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.'
});
}
if (name.length > 191) {
throw new InvalidOfferName({
message: 'Offer `name` can be a maximum of 191 characters.'
});
}
return new OfferName(name);
}
}
module.exports = OfferName;