Ghost/ghost/offers/lib/domain/models/OfferCurrency.js
Fabien O'Carroll 2b58ecd82e Added support for creating fixed offers with currency
refs https://github.com/TryGhost/Team/issues/1083

We now allow creating offers for a fixed amount, rather than a
percentage. These require a currency to be passed as a fixed amount is
meaningless without one.
2021-10-07 17:37:48 +02:00

19 lines
599 B
JavaScript

const ValueObject = require('../../shared/ValueObject');
const InvalidOfferCurrency = require('../../errors').InvalidOfferCurrency;
/** @extends ValueObject<string> */
class OfferCurrency extends ValueObject {
/** @param {unknown} currency */
static create(currency) {
if (typeof currency !== 'string') {
throw new InvalidOfferCurrency({
message: 'Offer `currency` must be a string.'
});
}
// TODO: Validate it is a country code we support?
return new OfferCurrency(currency);
}
}
module.exports = OfferCurrency;